Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

detecting active Word 1

Status
Not open for further replies.

pietersj

Programmer
Jul 11, 2001
8
BE
I can create a new instance from the Word.application object, but how can I detect if the Word-application is already active ?
 
save as macro autoexec On Error GoTo bye
Instances = 0
apps = AppCount() - 1
Dim winnames$(apps)
AppGetNames winnames$()
For i = 0 To apps
If InStr(1, winnames$(i), "Microsoft Word") Then
Instances = Instances + 1
End If
If Instances > 1 Then
MsgBox " There is currently another instance of Word For Windows running. "
' This instance will Close. ", 16
'AppClose()
i = apps
End If
Next
bye:
 
But how can i retrieve the active word.application object ??
 
Thanks for that,
but I need also the currently active "word.application" object.
So my own application can use this object to create a new doc - from a specified template - and fill in the docfields. All that stuff works fine with me, but i just need to know how i can reuse the active word.application object
 
You can use the GetObject method to attach to the current instance of Word. NOTE: If the user is running Outlook with Word as the default e-mail editor, you may find that winword.exe is running in the background (task manager) and will be detected as "Running" in the sample below. Unfortunatly, I have had trouble accessing and controlling this instance of Word from VB and found it easier to start a new instance for my program.

Code:
    Dim hApp As Object

    On Error Resume Next
    Set hApp = GetObject(, "Word.Application")
    If Err.Number <> 0 Then
        MsgBox &quot;Word is Not Running&quot;
    Else
        MsgBox &quot;Word is Running&quot;
    End If
Hope this helps!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top