Open a URL with Internet Explorer in a new tab (not a new window)

Posted on 2016-10-06
Last Modified: 2016-10-07
I am trying to get an already running instance of Internet Explorer to add a new tabbed page. This is the Delphi code I start with.:

  Temp : String;
  if FileExists('C:\Program Files (x86)\Internet Explorer\iexplore.exe') then begin
    Temp := '"C:\Program Files (x86)\Internet Explorer\iexplore.exe"';
  if FileExists('C:\Program Files\Internet Explorer\iexplore.exe') then begin
    Temp := '"C:\Program Files\Internet Explorer\iexplore.exe"';
  ShellExecute(Handle, 'open', PChar(Temp), PChar(''), nil, SW_SHOW);

Open in new window

Although this code does display the URL ( in IE, it does so by launching a new instance (new window) of IE rather than in a new tabbed page to the already running instance of IE.  How can I do the latter?
Question by:Fontographer
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 27

Accepted Solution

Sinisa Vuk earned 500 total points
ID: 41833123
I've managed to run multiple tabs using IE ole automation. First, check if iexplore.exe is running. If yes - then use Navigate2 function from that runing instance, but if not found - start new instance...
uses ComObj;
  navOpenInNewWindow = 1;
  navNoHistory = 2;
  navNoReadFromCache = 4;
  navNoWriteToCache = 8;
  navAllowAutosearch = 16;
  navBrowserBar = 32;
  navHyperlink = 64;
  navEnforceRestricted = 128;
  navNewWindowsManaged = 256;
  navUntrustedForDownload = 512;
  navTrustedForActiveX = 1024;
  navOpenInNewTab = 2048;
  navOpenInBackgroundTab = 4096;
  navKeepWordWheelText = 8192;
  navVirtualTab = 16384;
  navBlockRedirectsXDomain = 32768;
  navOpenNewForegroundTab = 65536;

procedure RunIEUrl(sURL: String; param: OleVariant);
  i: Integer;
  ShellWindows: OleVariant;
  ShellApplication: OleVariant;
  IE: OleVariant;
  IE := Unassigned;
  //find running instance - using win shell
  ShellApplication := CreateOleObject('Shell.Application');
  if not VarIsEmpty(ShellApplication) then
    ShellWindows := ShellApplication.Windows;
    for i := 0 to ShellWindows.Count - 1 do
      if UpperCase(ExtractFileName(ShellWindows.Item(i).FullName)) = 'IEXPLORE.EXE' then //check exe name
        IE := ShellWindows.Item(i);
        IE.Navigate2(sURL, param);

  //not found running instance - run new instance
  if VarIsEmpty(IE) then
    IE := CreateOleObject('InternetExplorer.Application');
    IE.Visible := true;

procedure TForm1.Button1Click(Sender: TObject);
  RunIEUrl(Edit1.Text, navOpenInNewTab);

Open in new window

Fill Edit1 with a web site url....

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi : could not find program, '...exe' 2 213
oracle global variables 4 80
Delphi: Connect to running MS Outlook 4 162
Delphi and Access based Enumeration 9 78
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question