View Full Version : Opening a Word Document within CURRENT Word Application


Motion
06-05-2008, 05:08 PM
Hi there

I am using the following code to open a Word Document:

Set oWord = CreateObject("Word.Application")

Set oDoc = oWord.Documents.Add(strHeaderLocation)


The problem is that each time a Word document is opened, it starts in a new application of Word rather than opening a new document within the current instance of Word.

Can somebody please help me with the code to open a Word document within the current instance of Word rather than creating a new Word application? I imagine i will also need to test whether Word is currently running so i can use my existing code if the user doesn't already have Word open.

Thanks

Richard

--------------------

I have such a bad habit of posting then solving my problem right away!

Solution was as follows:

Set oWord = Word.Application

boblarson
06-05-2008, 08:41 PM
On Error Resume Next
'attempt to get an existing running copy of Word
Set objWord = GetObject(, "Word.Application")
'if error occurred, then couldn't find Word, create new instance
If Err Then
Err.Clear
Set objWord = CreateObject("Word.Application")
End If