0
Shell ("C:\Program Files (x86)\Internet Explorer\iexplore.exe   https://google.com")

This will open a window in IE. What do I use to open more "tabs" instead of windows?

If I use the following, it will open two windows. Again, I want a window with tabs, not another window. I googled and only found code using dim or loop.

Shell ("C:\Program Files (x86)\Internet Explorer\iexplore.exe   https://google.com")
Shell ("C:\Program Files (x86)\Internet Explorer\iexplore.exe   https://bing.com")
Light
  • 1,206
  • 1
  • 9
  • 16

2 Answers2

0

I just learned if I add the following at the end of the code, it will open a tab. , Nothing, "_blank" However, this doesn't work if I want to open 3rd, 4th, etc.

0

This is not possible the way you are trying to do it. IE does not have a command line switch that allows multiple URL's to be opened in a new tabbed window like you want.

Try this:

Const navOpenInBackgroundTab = &H1000
my_favorite_search_engines = Array("lycos.com", "askjeeves.com", "altavista.com")
Set IE_obj = CreateObject("InternetExplorer.Application")
IE_obj.Visible = True
For Each site In my_favorite_search_engines
    waitTill = Now() + TimeValue("00:00:02")
    While Now() < waitTill
        DoEvents
    Wend
    IE_obj.Navigate2 site, navOpenInBackgroundTab
Next site

you'll need to dump it in a file my_cool_script.vbs using notepad, save it to your desktop, and run it.

borrowed the wait code from this answer: https://stackoverflow.com/a/11252660/6689725

Z4-tier
  • 7,287
  • 3
  • 26
  • 42
  • Your code works when I use your URLs; however, when I use my own URLs, it will only open two tabs and stops. The error message says "Method 'Navigate' of object 'IWebBrowser2' failed. – grignard Oct 21 '20 at 14:46
  • Here is another one that works the same as your code. But I encountered the same issue -- it only allows me to open two tabs and gives me an error message. ``` Sub Test() Dim IE As Object Set IE = CreateObject("InternetExplorer.Application") With IE .Navigate "https://lycos.com" '1st tab .Navigate "https://askjeeves.com", CLng(2048) '2nd .Navigate "https://altavista.com", CLng(2048) '3rd .Visible = True End With End Sub ``` – grignard Oct 21 '20 at 14:47
  • I think this might be caused by the loop executing too quickly. If you sleep for a couple seconds inside the `For Each` loop, that might fix it. – Z4-tier Oct 21 '20 at 14:48
  • I added 10 second wait time between each URL, and it's now tell me " The remote server machine does not exist or is unavailable." – grignard Oct 21 '20 at 14:55
  • What did you use to add the wait? I updated my post to include the wait. Also, can you update your original question with the new code you are working with? It is much easier that way instead of using the comments/ – Z4-tier Oct 21 '20 at 18:14