I am having a problem with automating an Excel file. The VBA script in Excel first opens a Word application and a Word document:
Dim wordApp As Object
Set wordApp = CreateObject("Word.Application")
vPath = Application.ActiveWorkbook.Path
Set wordDoc = wordApp.Documents.Open(vPath & "\test.doc")
And then I call the subroutine in the Word document, passing some data from the Excel file:
Call wordApp.Run("StartWithData", variable1, variable2)
If Excel detects an error in this routine, I will close the Word document and Word application from Excel in the shortcut that I call Err1:
On Error Goto Err1
'all the code from above
Exit Sub
Err1:
wordDoc.Close wdCloseWithoutSaving
wordApp.Quit SaveChanges:=wdDoNotSaveChanges
Set wordDoc = Nothing
Set wordApp = Nothing
This works fine under normal circumstances; however, if the Word document or application is closed before the label is executed Err1(for example, the user manually closes the document), I get the following error:
Runtime error '-2147417848 (80010108)':
Automation error The called object is disconnected from its clients.
, wordApp / wordDoc - , ( Nothing).
, : , , on error resume next?
Such as:
If Not isDisconnected(wordDoc) Then
wordDoc.Close wdCloseWithoutSaving
End If
If Not isDisconnected(wordApp) Then
wordApp.Quit SaveChanges:=wdDoNotSaveChanges
End If
1:
omegastripes, , , (wordDoc) . Word (wordApp) , :
'462':