Question

I'm trying to understand how the objIE.Document.body.innertext works. From what I've read, it's almost like CTRL+C, however, I'm trying to get it to work and something's missing. Here's the code:

Dim objIE
Dim strPrintText

Set objIE = CreateObject("InternetExplorer.Application")

objIE.Navigate "www.bing.com"
strPrintText = objIE.Document.body.innertext

msgbox(strPrintText)
Was it helpful?

Solution

You must wait until the browser is ready (and not use param list () when calling a Sub):

Dim objIE
Dim strPrintText

Set objIE = CreateObject("InternetExplorer.Application")

objIE.Navigate "www.bing.com"

Do Until objIE.readyState = 4 : Wscript.Sleep 10 : Loop

strPrintText = objIE.Document.body.innertext

msgbox strPrintText

Please cf this for background.

WRT param list () in Sub calls:

>> MsgBox "No param () when calling a Sub!", vbOkOnly
>>
>> MsgBox("No param () when calling a Sub!", vbOkOnly)
>>
Error Number:       1044
Error Description:  Cannot use parentheses when calling a Sub
>>
>> MsgBox "Do you believe me now?", vbOkOnly

For theory/reason cf this; and reflect on the merit of "it works" when discussing rules of programming (or ethics: stealing works fine, as long you are not caught).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top