简体   繁体   中英

VBA to open IE with tabs

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")

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM