Consulting

Results 1 to 7 of 7

Thread: Test KB code: automating internet explorer

  1. #1
    Knowledge Base Approver VBAX Expert brettdj's Avatar
    Joined
    May 2004
    Location
    Melbourne
    Posts
    649
    Location

    Test KB code: automating internet explorer

    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.
    1. 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
    2. Run the macro AutomateIE by going to Tools-Macro-Macros and double-click AutomateIE.
    [vba]
    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"
    '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"
    .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

    [/vba]

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Hi Dave,

    Excel 2000 SR-1, Win2000

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

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

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

    Matt

  3. #3
    XP SP2 Office XP wont run. I get a error undefined Sub AutomateIE()
    Dim ie As InternetExplorer

  4. #4
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    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

  5. #5
    Knowledge Base Approver VBAX Expert brettdj's Avatar
    Joined
    May 2004
    Location
    Melbourne
    Posts
    649
    Location
    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

  6. #6
    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?

  7. #7
    VBAX Regular
    Joined
    Sep 2005
    Posts
    34
    Location
    Quote Originally Posted by EricM
    XP SP2 Office XP wont run. I get a error undefined Sub AutomateIE()
    Dim ie As InternetExplorer
    Try Set ie = CreateObject("InternetExplorer.Application")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •