David Zhang
David Zhang

Reputation: 15

Assign a New Word Document to a Variable

I'm currently running a VBA macro in Word. Part of it requires creating a new blank document to run some of the work in. Right now, I just have Documents.Add DocumentType:=wdNewBlankDocument which I then refer to through Windows("Document1").Activate.

However, the problem is that if I want to run the macro more than once, it won't work because whenever it creates a new blank document, it will become "Document2/3. etc.". I basically need to assign a blank document to a variable so I can call it reliably. I know how to do this with documents that are already saved (ones that have a filename/filepath), but not sure what it would take for a new/blank document.

I'm currently working in Word 2007.

Upvotes: 0

Views: 1067

Answers (1)

Cindy Meister
Cindy Meister

Reputation: 25663

Absolutely no problem:

Dim oDoc as Word.Document
Set oDoc = Documents.Add(DocumentType:=wdNewBlankDocument)

Upvotes: 1

Related Questions