Opening a Word Document within CURRENT Word Application

Motion

Registered User.
Local time
Today, 17:58
Joined
Oct 30, 2007
Messages
11
Opening a Word Document within CURRENT Word Application - SOLVED!

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
 
Last edited:
Code:
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
 

Users who are viewing this thread

Back
Top Bottom