Consulting

Results 1 to 7 of 7

Thread: Opening multople tabs in IE from Excel and VBA

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Mar 2013
    Posts
    2
    Location

    Opening multople tabs in IE from Excel and VBA

    I have been programming for a few years, but am fairly new to VBA. I am trying to write a script at work and VBA is all we have access to.

    I have an excel sheet with a few thousand links on it and I am writing a script that searches through them for a few in particular and then needs to open four links in a new internet explorer window in separate tabs.

    I have the rest of the program working to find the right 4 links, and then I call this function to open them and this is where it causes problems.

    Function openLinks(url1, url2, url3, url4)
    Set WshShell = CreateObject("WScript.Shell")
    Set ie = CreateObject("InternetExplorer.Application")
    ie.navigate url1
    ie.Navigate2 url2, 2048
    ie.Navigate2 url3, 2048
    ie.Navigate2 url4, 2048
    End Function
    This function seems to work in principle, but it only opens 2 or 3 tabs before giving me this error:

    Run-time error '-2147467259 (80004005)':

    Method 'Navigate2' of object 'IWebBrowser 2' failed
    the strange thing is that it will usually open 2 tabs, but sometimes 3 before throwing an error and very occasionally it will open all 4 without error. I can run it 5 times in a row without changing anything and it is random how many work.

    I searched Google already and followed a suggestion to slow it down between opening tabs by entering this between them.

     While ie.Busy
    DoEvents
    Wend
    And this made no diference at all.

    I then read a suggestion to add this between tabs to slow it down, with varying lengths of time.
     Application.Wait DateAdd("s", 1, Now)
    and this made things worse. it now errored on the very next navigate2 call after the delay. In fact, if I used both, then it would error on the very next call to check ie.busy after a delay too.

    Has anybody come across this kind of issue before? or has any suggestion to get this working? I'm especially confused because of the intermittant nature of the problem.

    Thank you for any help you can offfer.
    Last edited by Aussiebear; 10-04-2022 at 11:58 PM. Reason: Adjusted code tags

Posting Permissions

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