BUG: Starting Word Manually Uses Same Instance as AutomationID: Q188546
|
You run a Visual Basic application that uses the CreateObject function to start a hidden instance of Microsoft Word. The application is idle, but it still maintains a reference to Word. Next, you manually start an instance of Word. A separate instance of Word should open, but the same instance that was created by the Visual Basic application is made active instead. If you close Word and continue to work in the Visual Basic application, the following error occurs when the application tries to use Word objects because Word is no longer running:
This automation error translates to "The RPC server is unavailable."Run-time error '-2147023174 (800706ba)':
Automation error
Use one of the following to work around this problem:
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
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
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 Window Explorer, typically when someone double-clicks a document.
Additional query words: OLE automation
Keywords : kbAutomation kbWord kbGrpDSO kbOffice2000 kbVBA500 kbword2000
Version : WINDOWS:2000,5.0,97; :
Platform : WINDOWS
Issue type : kbbug
Last Reviewed: June 3, 1999