PDA

View Full Version : Test KB code: automating internet explorer



brettdj
03-28-2005, 04:45 PM
This code has been put forward as a KB sample and one of the testers has a problem with using the Microsodt Internet Controls Library. Can people please test this and let me know if it works and what system detauils (Excel and Windows) they are using.

This code runs a google search for "vbax kb". If a valid website is found via a regular expressions parsing search, then this web page is opened.

Run the macro SetRefs by going to Tools-Macro-Macros and double-click SetRefs. This sets the references to the VBscript Regular Expressions 5.5 and Internet Controls libraries
Run the macro AutomateIE by going to Tools-Macro-Macros and double-click AutomateIE.

Sub AutomateIE()
Dim ie As InternetExplorer
Dim RegEx As RegExp, RegMatch As MatchCollection
Dim MyStr As String
Set ie = New InternetExplorer
Set RegEx = New RegExp
'Search google for "vbax kb"
ie.Navigate "http://www.experts-exchange.com (http://www.experts-exchange.com/)"
'Loop unitl ie page is fully loaded
Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop
'String to parse google search for a VBAX reference
With RegEx
.Pattern = "www.vbaexpress.+?html (http://www.vbaexpress.+/?html)"
.MultiLine = True
End With
'return text from google page
MyStr = ie.Document.body.innertext
Set RegMatch = RegEx.Execute(MyStr)
'If a match to our RegExp searchstring is found then launch this page
If RegMatch.Count > 0 Then
ie.Navigate RegMatch(0)
Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop
MsgBox "Loaded VBAX link"
ie.Visible = True
Else
MsgBox "No VBAX link found"
End If
Set RegEx = Nothing
Set ie = Nothing
End Sub
Sub SetRefs()
Dim ObRef
On Error Resume Next
' Adds VBscript ref and Internet Controls
With ThisWorkbook.VBProject
.References.AddFromGuid _
"{3F4DACA7-160D-11D2-A8E9-00104B365C9F}", 5, 5
.References.AddFromGuid _
"{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 1, 1
End With
End Sub

mvidas
03-29-2005, 10:26 AM
Hi Dave,

Excel 2000 SR-1, Win2000

Didn't work as is, but after making the following adjustment:

' ie.Navigate "http://www.experts-exchange.com (http://www.experts-exchange.com/)"
ie.Navigate "http://www.google.com/search?q=vbax+kb"

It worked fine, brought up http://www.vbaexpress.com/kb/archive.php/a-2.html

Matt

EricM
03-29-2005, 10:50 AM
XP SP2 Office XP wont run. I get a error undefined Sub AutomateIE()
Dim ie As InternetExplorer

mvidas
03-29-2005, 11:10 AM
Eric,
As it is 6am in Dave's neck of the woods right now, maybe I can help. Did you run his step #1 above first, running the macro SetRefs to programatically set the references to MS Internet Controls and Regular Expressions?

Also, glad to see another upstater on here :) I'm in Rochester (probably 2.5 hours from you?), only one other person here that I know of (JOrzech, also from Rochester).

Welcome!
Matt

brettdj
04-03-2005, 08:52 PM
Thanks Matt

see http://www.vbaexpress.com/forum/showthread.php?t=2522

The problem for John turned out to be some redundant but missing library references

Cheers

Dave

jfdobbs15
01-02-2008, 09:45 AM
I get a compile error on the "Dim RegEx ..." expression. I suspect it may be due to the reason given in Dave's last post. Could you tell me whether I should unselect and reselect any references?

chrismc
02-19-2008, 01:44 PM
XP SP2 Office XP wont run. I get a error undefined Sub AutomateIE()
Dim ie As InternetExplorer

Try Set ie = CreateObject("InternetExplorer.Application")