PDA

View Full Version : innerHTML not returned?



mstrebl1990
09-09-2018, 12:35 PM
Hi everyone.

I have tried this code in Excel 13 and 16, and in neither does it return the html I am looking for. I am trying to extract a substring from it, which has worked on other websites, but I can't get the initial html to process. I have a UserForm with a command button that calls the code below, and a textbox called TextBox1. The lines I commented out are causing an error in excel 16. Here's the code:

Private Sub CommandButton1_Click()

'the_start
Dim objIE As Object

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Top = 0
objIE.Left = 0
objIE.Width = 800
objIE.Height = 600
objIE.Visible = True

On Error Resume Next


objIE.navigate ("https://bethematch.org/tcdirectory/index/35/")

Do
DoEvents

If Error.Number <> 0 Then
objIE.Quit
Set Obj.IE = Nothing
'GoTo the_start

End If
Loop Until objIE.readystate = 4


TextBox1.Text = objIE.document.body.innerHTML


End Sub

I tried showing the html in a msgbox but it's cut off and I am not sure if it's the correct html. I would really appreciate any help. Is there any other way to get the html for processing? It's a website specific issue, totally works for other websites.

Thanks everyone!!

Best,
Martin

p45cal
09-09-2018, 03:32 PM
Here your code quickly quit IE repeatedly, for ever looping.
The the_start line should be:
the_start:
with a colon at the end.

This worked for me, but you'll need a reference to MS Forms, which if there's a userform in your project you probably already have, but if you haven't the easiest way to do this is to add a userform to the project in the vbe and remove it straightaway!

Private Sub CommandButton1_Click()
Dim objIE As Object

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Top = 0
objIE.Left = 0
objIE.Width = 800
objIE.Height = 600
objIE.Visible = True
'On Error Resume Next
objIE.navigate ("https://bethematch.org/tcdirectory/index/35/")
Do
DoEvents
Loop Until objIE.readystate = 4
zzz = objIE.document.body.innerHTML
Set myData = New DataObject
myData.SetText zzz
myData.PutInClipboard
objIE.Quit
End Sub
I didn't set up a userform with a textbox, I put the data into the clipboard, so when the macro's finished you need to paste it into say, notepad.

mstrebl1990
09-09-2018, 08:17 PM
That totally fixed it. Thank you so much!!