1
votes

What's the best way to open multiple work documents? I want to be copying/pasting from different word documents through VBA. Should I open a new instance for each one? I really need two workbooks active at a time, and will close after the pasting has been done.

Is

Set objWord1 = CreateObject("Word.Application")
Set objWord2 = CreateObject("Word.Application")
objWord1.Document.open("maindocument.docx")
obj2Word2.Document.open("seconddoc.docx")

is this the most efficient way?

1

1 Answers

2
votes

You just need one instance of the application open. Then you can make two separate declarations for your documents:

Dim objWord As Object
Dim doc1 As Object, doc2 As Object

Set objWord = CreateObject("Word.Application")
Set doc1 = objWord.Documents.Open("maindocument.docx")
Set doc2 = objWord.Documents.Open("seconddoc.docx")

I don't generally recommend this, but if you want to get crafty:

Dim doc1 As Object, doc2 As Object

With CreateObject("Word.Application")
    Set doc1 = .Documents.Open("maindocument.docx")
    Set doc2 = .Documents.Open("seconddoc.docx")
End With