Article ID: 188546
Article Last Modified on 1/23/2007
-or-
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Option Explicit
Dim wrdApp As Word.Application
Private Sub CreateWordObject()
'Test if object is already created before calling CreateObject:
If TypeName(wrdApp) <> "Application" Then
Set wrdApp = CreateObject("Word.Application")
End If
End Sub
Private Sub UseWordObject()
MsgBox TypeName(wrdApp) 'if displays "Application" then
'Reference to Word is valid, else reference is invalid and
'an error occurs on the following line:
MsgBox wrdApp.Name
End Sub
Private Sub CloseWordObject()
If TypeName(wrdApp) = "Application" Then
wrdApp.Quit SaveChanges:=wdDoNotSaveChanges
Set wrdApp = Nothing
End If
End Sub
Private Sub CreateWordObject()
Dim temp As Word.Application
'Test if object is already created before calling CreateObject:
If TypeName(wrdApp) <> "Application" Then
Set temp = CreateObject("Word.Application")
Set wrdApp = CreateObject("Word.Application")
temp.Quit
Set temp = Nothing
End If
End Sub
NOTE: This workaround does not work when a document is launched directly through the Windows Explorer, typically when someone double-clicks a document.
Additional query words: OLE automation
Keywords: kbautomation kbbug kbpending KB188546