Code: Select all
Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
Selection.Style = ActiveDocument.Styles("Heading 1")
Selection.TypeText (strcURLHeader & strURL & vbCrLf)
Selection.Style = ActiveDocument.Styles("Normal")
Selection.TypeText (strcSearchStringHeader & strSearchTerm & vbCrLf)
DoEvents ' TWO DOEVENTS ATTEMPT TO OVERCOME TIMING PROBLEMS WITH SOME SEARCH ENGINES.
Selection.TypeText (bot.ActiveElement.Text)
DoEvents ' TWO DOEVENTS ATTEMPT TO OVERCOME TIMING PROBLEMS WITH SOME SEARCH ENGINES.
doc.SaveAs (strFilename)
My Word2003/VBA code sends a search request to eight search engines, one at a time, through the Chrome Browser, and attempts to capture the search results (text) in a Word document. "Selection.TypeText (bot.ActiveElement.Text)"
Three of the search engines occasionally do not respond in time, and instead of storing the web page (lots of hits!) in the document I get stored just the preamble. So I know that I am executing my code - the URL and search string are dumped, buit not the web page contents (bot.ActiveElement.Text).
If I set a break point to introduce a manual delay, the text is dumped correctly..
The two "DoEvents" are not [always] successful in introducing a delay. And once I get the bit between my teeth and turns this loose, I will not see or know that text is missing!
I think that there is nothing special about the Chrome Driver ("bot"). From Word/VBA's point of view the world out there is a black box and I am waiting for something to come in from the black box.
Excel has WAIT, but Wordies have to depend on SLEEP. (Microsoft Regular Expressions v 1.0 in my case)
If/When I introduce a SLEEP of one second in my VBA code, exactly what goes to sleep?
Word/VBA code for sure; my procedure gets nothing done until after that one-second is up.
Windows can't go to sleep, not totally, or else it would never wake up!
(1) Is the Chrome Driver (bot) going to sleep now? If so that won't do much to help me over the timing problems.
(2) The general question is "How much of the black-box world out there is going to sleep? And what is NOT going to sleep?
Thanks
Chris