I’m using VBA in Excel 2007. On an excel userform there four controls:
- a single multipage control
- an active x webbrowser control on page1 of the multipage control
- a textbox control on page2 of the multipage control
- a list box control on the userform
I’m trying to pass the loaded webbrowers document innerhtml to the textbox control using the onchange event but keep getting error 91 Object variable or With block variable not set. What am I doing wrong?
Here is the code:
Private Sub MultiPage1_Change()
Dim strhtml As String
Dim strSelectItem As String
strhtml = ""
If IsNull(Me.ListBox1.value) Then
MsgBox "No Source View selection made. Have gone with 'Doc innerHTML'"
Me.ListBox1.Selected(0) = True
strSelectItem = "Doc innerHTML"
Else
strSelectItem = Me.ListBox1.value
End If
Select Case strSelectItem
Case "Doc innerHTML"
strhtml = WebBrowser1.Document.documentElement.innerhtml
Case "Doc innerText"
strhtml = WebBrowser1.Document.documentElement.innerText
Case "Body innerHTML"
strhtml = WebBrowser1.Document.body.innerhtml
Case "Body innerText"
strhtml = WebBrowser1.Document.body.innerText
End Select
' strhtml = WebBrowser1.Document.documentElement.outerhtml
MultiPage1.value = 1
MultiPage1.Pages(1).TextBox2.value = ""
MultiPage1.Pages(1).TextBox2.value = strhtml
End Sub
Private Sub UserForm_Initialize()
'Disable the Back button
CommandButton2.Enabled = False
'Disable the Forward button
CommandButton3.Enabled = False
With Me.ListBox1
.AddItem "Doc innerHTML"
.AddItem "Doc innerText"
.AddItem "Body innerHTML"
.AddItem "Body innerText"
End With
End Sub