Stopping multiple instances of WORD opening

J

JM7

I am calling the lines below from ACCESS.

Everytime this function is called I get new instances of WORD 2002 opening.
Set objword = CreateObject("Word.Application")

Set wrddoc = objword.Documents.Open("d:\temp\test.doc")

I can't use
Set objword = GetObject("Word.Application")
because it results in an error even if WORD is running

Thanks in advance
 
T

Tom Wickerath

JM7:

What happens if you use:
Set objword = GetObject(, "Word.Application") instead of
Set objword = GetObject("Word.Application")

Note the leading comma and space after the opening parenthesis. If there is
no active instance of Word, you can trap for error 429 and use CreateObject
instead. Something like this:

Dim appWord As Word.Application

On Error Resume Next
Set appWord = GetObject(, "Word.application")
If Err = 429 Then
Set appWord = CreateObject("Word.Application")
Err = 0
End If


Tom
_______________________________________

:

I am calling the lines below from ACCESS.

Everytime this function is called I get new instances of WORD 2002 opening.
Set objword = CreateObject("Word.Application")

Set wrddoc = objword.Documents.Open("d:\temp\test.doc")

I can't use
Set objword = GetObject("Word.Application")
because it results in an error even if WORD is running

Thanks in advance
 
J

jm7

Thanks Tom

Just repositioning the comma did wonders. From my perusal of the NET I had
thought the following was OK: but it would not work

Set objword = GetObject("Word.Application"), "Word.Application")

John
 
T

Tom Wickerath

Hi John,

Glad to help. By the way, I believe the first parameter is used to specify
the name of a document that is currently open, as indicated in this KB
article (example given for Excel):

http://support.microsoft.com/?id=288902

From this KB article:
"You can attach to a specific instance if you know the name of an open
document in that instance. For example, if an instance of Excel is running
with an open workbook named Book2, the following code attaches successfully
to that instance even if it is not the earliest instance that was launched:

Set xlApp = GetObject("Book2").Application


Tom
________________________________________

:

Thanks Tom

Just repositioning the comma did wonders. From my perusal of the NET I had
thought the following was OK: but it would not work

Set objword = GetObject("Word.Application"), "Word.Application")

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top