Link to home
Start Free TrialLog in
Avatar of dwe0608
dwe0608Flag for Australia

asked on

VB6 and MsWord in a Webbrowser Control

Hi Guys

In the following function:
Private Sub wb_NavigateComplete2(ByVal pDisp As Object, url As Variant)
   
   'On Error Resume Next
   Set oDocument = pDisp.Document

   MsgBox "File opened by: " & oDocument.Application.Name
   
   If (pDisp Is wb.Object) Then
            'Debug.Print "wb_NavigateComplete2 = " & Now() & " - " & url
            'MsgBox "Complete - " & url
            bDoneDownloading = True
    End If

   ' hide tools bars
   wb.ExecWB OLECMDID_HIDETOOLBARS, OLECMDEXECOPT_DONTPROMPTUSER
End Sub

Open in new window


when I unload the browser control, it fails on this line:

MsgBox "File opened by: " & oDocument.Application.Name

with an error 438 saying object doesnt support this property or method.

To avoid the use of "on error resume next", how would I fail gracefully.

I have tried navigating away from the word document by implementing a function
Public Sub UnloadWord()
   wb.Navigate2 "about:blank"  ' So that webbrowser starts in 'msWord mode' and empty document
End Sub

Open in new window


which is called in the form unload event

MTIA

DWE
ASKER CERTIFIED SOLUTION
Avatar of dwe0608
dwe0608
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Guy Hengel [angelIII / a3]
relying on the file extension is not the safest way, but shall work in most practical cases.

other technique would be to check if oDocument is nothing, and if not, then check oDocument.Application (if it's nothing or not), and finally use oDocument.Application.Name aso..
Avatar of dwe0608

ASKER

no expert assistance in arriving at the answer