Free Microsoft Excel 2013 Quick Reference

[Solved] VBA: Opening Internet Explorer

I have a user form in Excel 97 that shows a website address. Is it possible to have a button that opens Internet Explorer and goes to the URL in the userform? Is there any code available to do this?

Any help appreciated.

Post your answer or comment

comments powered by Disqus
I am looking for a method to open internet explorer 9 as "InPrivate" mode so that I can log into a site under multiple logins.

Private Sub LaunchCRM()
    Dim TimeOutCheck As Integer
    TimeOutCheck = 0
    USERNAME = Cells(Cells(2, "A").Value + 2, "C")
    PASSWORD = Cells(Cells(2, "A").Value + 2, "D")
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate "WEBSITE"
    IE.Visible = True
    AppActivate IE
    Do While FindWindow(vbNullString, "Windows Security") = 0 And FindWindow(vbNullString, "Connect to") = 0
        Application.Wait DateAdd("s", 1, Now)
        TimeOutCheck = TimeOutCheck + 1
        If TimeOutCheck = 15 Then
            MsgBox ("Timed out due to window not existing." & vbNewLine & "Please try again.")
            Exit Sub
        End If
    Call FillLogin(USERNAME, PASSWORD)
    Call SetNumLockKey(True)
    If Cells(1, "A").Value = True Then
        Application.OnTime Now + TimeValue("00:00:01"), "LoginPrompt"
    End If
End Sub
How could I go about opening multiple instances of IE while keeping cookies isolated for each one, the only method I can think of is to open IE in its private mode. However after a significant amount of searching I haven't seen a function to do that. I am trying to avoid the "Application.SendKeys (Ctrl/Shift + P)" method and launch private IE (and set it as an object).

Thanks in advance.

I am currently using the following code to open an Internet Explorer window, so that I can fill out and submit an online form.

Dim IE As InternetExplorer
Set IE = New InternetExplorer

With IE
.Visible = True
.Navigate "URL"
End With

However, when I go to the page in question a pop-up window appears. I therefore need to be able to close the pop-up window, or make the original (parent) window active, before I can submit the form. Does anyone know how I can do this?

Any help much appreciated - Thanks

Hi Everyone,

Setup: We have a file which is constantly being updated that users need to access and work with. Due to the spread of the users (and access rights) they cannot all have access to the server it is kept on so we have come up with the idea to keep it on the company intranet where it can be refreshed by us and downloaded by the user. The reason why we would like to kick this action out of Excel is slightly more complicated but hopefully the below will be enough to go on.

I'm trying to write a macro in Excel that will accomplish the following;

1) Start Internet Explorer (IE)
2) Navigate to an address
3) Select a file to Download
4) Either open/save this file
5) Access this file and start a macro within it.

I can get steps 1, 2 and 3 done but then I come across problems.

Is there a way to get IE to just pick the open or save option on the download dialogue box rather than having the user select it?

Option 1 - Force to 'Open'
If the option is selected to open and then you end up with the application (in this case PowerPoint) embedded in IE, is there a syntax that allows you to control the embedded application?

Option 2 - Force to 'Save'
If the option can be forced to save, can I capture the save location selected? (That way I could open the document and operate it much more easily)

All thoughts and any other options to put into the fray here would be more than welcome.

Thanks in advance,

Hello everyone, i need some help with a little project im doing. im using excel vba for this. i have a worksheet that has a list of items and i need the urls for all of them, so to get them im using internet explorer. i have the code to open internet explorer to the right page but after that nothing. i have worked 4 days on trying to figure out how to do it. so what im trying to get the program to do it go to a page then search the web page for the first product in cell A1 then click the link for that item on the web page. then on the item page it needs to copy the url and paste it in cell B1. but if it doesn't find the item on the first page it will have to go to the second page and search there for the item. here is what i have so far:
Sub LaunchSite()

Dim ie As Object
Dim Find As String

Set ie = CreateObject("InternetExplorer.application")
ie.Visible = True

Find = "OKGEAR 18" & " Straight To Left Angle SATA 6Gbit/s Cable Model GC18AKM12-SL - Retail"

While ie.busy
  DoEvents  'wait until IE is done loading page.

'search page 1
If ie.getElementById(Find).Value Like Find Then
 'search page 2

    If ie.getElementById(Find).Value Like Find Then
    'search page 3
        If ie.getElementById(Find).Value Like Find Then
        End If
    End If
End If
dont worry about the list of items i know how to change Find for the cells i just need it to run through once and then i can modify it to run as much as i need. the site is in the code its the ie.Navigate.

thanks for any help.


I have an annoying problem in excel 2007 that I would love some assistance on. I have an excel 2007 spreadsheet with hundreds of hyperlinks to jpg photos in it. I have set the default program in Excel as windows picture viewer, and thats the program that opens jpg's everywhere on my PC. However within excel hyperlinks are opened in Internet Explorer 8.

I have searched the web and a solution has been posted several times to add the below registry key:


I have tried this, restarted excel, and restarted windows 7 but it has not resolved my issue. It seems that this issue resolves the problem in earlier versions of Windows and Excel, but not the combination of Windows 7 and IE8.

2) Others were suggesting this was an issue with IE8 itself, so I have now completely uninstalled IE8 (I use firefox so don't need it anyway). Now when I try to open a hyperlink in excel 2007 I get the error "No program is registered to open this file".

This is super frustrating, can anybody assist?

Mornign all,
I have already gotten some help with this code and I am close to having it to do exactly what I want.

The macro I have opens Internet Explorer to a webpage clicks a button which opens a new page with all the data I need and then selects and copies all the data.

The problem I have is when it clicks the submit button that data is opened in a new Internet Explorer window so the copy and paste feature copies the old page which is not the data I need. I need it to copy from the new page that opens.

Sub Websearching()

Dim ie As Object
Dim ieDoc As Object
Dim SubmitBtn As Object


ie.Visible = True

While ie.busy

Set ieDoc = ie.Document

Set SubmitBtn = ieDoc.getelementById("submit1")


While ie.busy '**I need it to loop here while the Document opens as it takes a few 
DoEvents       '**seconds for it to open.  I tried ieDoc.busy and that didn't work

'**Here it copies and pastes from the original page it opened I need it to copy from
'**the new ie.Document that is opened

ie.Visible = False


Set ie = Nothing
Set ieDoc = Nothing
Set SubmitBtn = Nothing

End Sub


I have a problem where an application, which I can only run in Internet Explorer, must open spreadsheets in Excel 2002 and otherwise, whether any other web browser or just some files on my desktop, have to be opened in Excel 2007. I have both versions currently installed. Does anybody know how I can configure Excel 2002 to open Internet Explorer files automatically?


How do you refer to the open internet explorer objects collection? For example, I want to run a For Each Next loop on all of the internet explorer objects that are open.

Is there a way of submitting a login request, which then sends a new web page... and then processing the resulting page. I'd like to do this without opening Internet Explorer and pumping keys into the form.

I'm currently using CreateObject("Microsoft.XMLHTTP") to GET files from the internet, but I need to get past the login screen first. Currently the user has to log in each time they want to use this tool.



Hi everybody,

I found an example code on the internet on how you can take over control of an already opened internet explorer application.
It all works perfect exept that I can't identify my element on a website cause it's a javascript.

Const myPageTitle As String = "Wikipedia"
Const myPageURL As String = ""
Const mySearchForm As String = "searchform"
Const mySearchInput As String = "searchInput"
Const mySearchTerm As String = "Document Object Model"
Const myButton As String = "searchButton"

Dim myIE As SHDocVw.InternetExplorer

  'check if page is already open
  Set myIE = GetOpenIEByTitle(myPageTitle, False)
  If myIE Is Nothing Then
    'page isn't open yet
    'create new IE instance
    Set myIE = GetNewIE
    'make IE window visible
    myIE.Visible = True
    'load page
    If LoadWebPage(myIE, myPageURL) = False Then
      'page wasn't loaded
      MsgBox "Couldn't open page"
      Exit Sub
    End If
  End If
  With myIE.Document.forms(mySearchForm)
    'enter search term in text field
    .elements(mySearchInput).Value = mySearchTerm
    'press button "Go"
  End With
End Sub
this is the element where I need to send a click to.

HTML Code: 
as you can see there is no tag or name in it. So I don't know on what, or how I can run this element.

The code above is what I need to run, but I don't know what to put in place of the "myButton".

Any ideas??

I have very limited programming knowledge and am a beginner.

I have code to open Internet Explorer from Excel. The website I am
accessing requires me to input a username and password. I want to know

if there is a way to do that from Excel.

I have an example of some code that opens an application, names the
application as MyScreen, and then runs the following:

If MyScreen.Search("Userid:",14, 5) = "Userid:" Then

I'm assuming that the "Search" looks for the ("Userid:") text, but I
have no idea what the ",14, 5) = "Userid:" is for.

My thinking is that I can do a similar thing with the Internet Explorer

Browser--name it, and then send keys to the username and password
boxes. I'm sure there is a better way, but I'm working with what I

Once I've logged into the internet site I then have to click on two
separate links to get to a point where I can input information, click a

submit button, and then obtain results from a separate browser that
opens with the results output in the form of a hyperlink. I click on
the results output hyperlink and I have what I'm looking for.

Any ideas for using Excel code to run through these steps is much




I am stuck and after some help...

I have written a macro which opens internet explorer, fills in the relevant fields then submits the form. occasionally a popup window will appear asking for confirmation which i want to focus on and click the confirm button and then carry on inputting data onto the original internet explorer window. i have been told to use a withevent but i cannot get it to work.

this is what i have so far:

this is the code in class1
Public WithEvents IeWe As InternetExplorer

Private Sub IeWe_NewWindow2(ppDisp As Object)
    Dim PopupWin As InternetExplorer
    Set PopupWin = ppDisp

    'code to click button
End Sub
this is the code in a module
Dim newopenwin As New Class1

Public Sub gogogo()

Dim ie As InternetExplorer
Dim objCollection As Object
Dim objCollection2 As Object


Set objCollection = ie.document.getElementsByTagName("td")
j = 0
while j < objCollection.Length
    If objCollection(j).ID = "addLinkSum" Then

       Set objCollection2 = objCollection(j).getElementsByTagName("a")
       k = 0
       While k < objCollection2.Length
           If objCollection2(k).innerText = "Add" And added = 0 Then
               'when link is clicked popup window appears
           End If            
           k = k + 1

   End If
   j = j + 1

can anybody please help??


How do I open internet explorer to with Excel 2007? I have code that works for one website but when I try it for it says "User-defined type not defined." Why is it being so fickle? Here's my code:

Private Sub CommandButton8_Click()
    Dim IEapp As Object
    Dim Password As String
    Dim UserName As String
    Dim URL As String
    URL = ""
    Set IEapp = New InternetExplorer
    ' Launch Internet Explorer and go to the site
      With IEapp
        .Visible = True
        .Navigate URL
      End With
    ' Wait until Internet Explore finishes loading
      While IEapp.Busy

End Sub

I currently have a macro that opens internet explorer fills in the drop downs and selects the check boxes I need. Then it clicks the submit button. The information is then displayed on the same webpage in an iframe. I have tried to select all and copy paste but that returns all of the area around the iframe. I am trying to find a way to select that data the appears in the iframe and copy that to my database.
Sub diputes()
Dim ie As Object
Dim ieDoc As Object
Dim btn As Object
Dim UserN As Object
Dim Bgroup As Variant


ie.Visible = True

ie.Navigate ""

While ie.Busy

ie.Document.getElementById("chkGroup").Checked = True

ie.Document.getElementById("drpBid").Value = "11"

ie.Document.getElementById("lstBxCallType").Value = "194"

ie.Document.getElementById("drpReportStyle").Value = "DAILY - SINGLE MONTH"

ie.Document.getElementById("txtDate").Value = Format(Date, "7/1/2010")


While ie.Busy


Set ie = Nothing
Set ieDoc = Nothing
Set btn = Nothing


End Sub


I've got VBA opening internet explorer and navigating to a page. I can also make it fill a value in a text box if the html form that contains the text box has a name.

The problem I've got is filling in a text box on a form that has no name.

An example is:

    Set ie = CreateObject("InternetExplorer.Application") 
    ie.navigate "" 
    Do While ie.busy And Not ie.readystate = 4 
    ie.Visible = True 
    Set ipf = ie.Document.all.Item("f").Item("q") 
    ipf.value = ("Bob") 
End Sub 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
...where "f" is the form name and "q" is the text box name.

Can anyone help please?




Does ANYBODY know if excel VBA can let Internet Explorer quit if it have been running when you open excel workbook? Thank you very much in advance.


I have created a macro that opens up a page, enters text into two separate txtboxes, then clicks a submit button... The problem is, there is an error that happens if a pro (value of txtpro) is invalid. This message is displayed using a label called lblError. I have tried to capture that value in an if then statement to paste the pro that caused the error to the right of it.

Below is my code, which works perfectly, except for the error value...even when it does this it still keeps going to the next cell. I will put the If then statement I tried to use below commented out.

Thanks in advance for any suggestions

Doug Polancih Jr

    Dim IE As SHDocVw.InternetExplorer 
    IE.Navigate "http://intranet.BLAHBLAH" 
    IE.Visible = True 
    Do While IE.Busy Or IE.ReadyState  READYSTATE_COMPLETE 
    Do While ActiveCell.Value > 0 
        IE.Document.forms(0).txtPro.Value = ActiveCell.Value 
        IE.Document.forms(0).txtReceiverName.Value = "All Short T2" 
         'HERE IT IS if ie.document.forms(0).lblError.value="IL/Cartage must be specified for the shipments of types 2 and 4"
then activecell.offset(5,0).text="Error" else
        Do While IE.Busy 
         'if IE.document.forms(0).lblError.text="
        ActiveCell.Offset(1, 0).Select 
End Sub 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines


Oops I forgot to include the html code of the label I am trying to capture... I have been doing VBA for a little while now, but not using it on Internet Explorer.

The code that I am trying to capture is:

and if it contained the error that I am trying to capture it would be

No shipment found for the pro 202-254996-9.

To anyone that replies thanks in advance.

--Doug Polancih Jr

Hi, A newbe here to the forum. Familiar with VBA in excel but now with interacting with internet explorer. After opening an internet explorer and a url from an excel vba program I want to save the contents returned as a text file so I can then extract various information.

Here's code I found to open IE and am starting with. What I can't figure out is an east way to save the internet explorer results as a text file.

 t = CreateObject("InternetExplorer.application") 
t.Visible = True 
t.Navigate "http://...." 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines

opening powerpoint and internet explorer from an access form...?

thank you.

I'm new at this, so bear with me. I'm using vba to navigate around in internet explorer. Basic stuff, really. Opening links and saving files to folders and so on and so forth. I've noticed on one instance that when I use vba to open up a page, the page I open doesn't have all the graphics displayed and the vba stops performing properly after that. When I navigate to this exact same web page manually, all is well. Any ideas out there as to what it is might be going awry?

I want to retrieve data off a web page using VBA. I reused some code I found on this site - reuse is a WONDERFUL thing. I am able to get IE
(Internet Explorer) to start up, and navigate to the page I want
however... I am having a few problems

1) I really don't want IE visible - I have the visible property set to
false but it doesn't seem to work

2) I can't seem to tell - in code - when the page is really finished loading. As
my code runs, IE starts/opens up, and the computer focus is on IE -
while MS Excel is sitting there in the background and nothing happens
until I MANUALLY make MS Excel the program with the focus.

Based on the code.... I thought

I have Windows VISTA and Excel 2007 however, I will run this code on XP with Excel 2003.

My code is below

Any ideas/thoughts would be appreciated


- - - - - - - - - - - - -

Dim myUrl As String
Dim strSearchString As String
Dim curDoc As Variant, curElement As Variant
Dim objIE As Object

'Set the vars
strSearchString = "<div class=""ds-list"">"

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = False ' This DOES NOT work for me

myUrl = ""

objIE.navigate myUrl

Do Until objIE.Busy
Application.Wait DateAdd("s", 1, Now)


MsgBox "It should NOT be busy now" & Chr(13) & "The current state
is: " & objIE.ReadyState
' If objIE.Busy = False Then
'Get the data from the web page used Document Object model
'End If

Hello, I'm having a strange problem working with Excel 2010, which I just installed. I'm am opening a new instance of Microsoft Internet Explorer and sending the command to navigate to any URL. It works fine up to this point, but when I try to access the ie.object after that, I get the RunTime error 8010108 or 80004005, whiich tells me it has disconnected from the object or has suffered an automation unspecified error. I don't know why this is happening. I've been using the same code in other versions successfully for probably 7 years. Has anyone seen this problem before? Could it be a permissions problem? Something I'm overlooking?

Here is the very simple code I'm using:

Sub openIE()
    Dim IE As InternetExplorer
    Dim MyStr As String
    Set IE = New InternetExplorer
    'Search google for "VBA Excel Automation"
    IE.Navigate2 ""
    'Loop unitl ie page is fully loaded
    Do Until IE.readyState = 4
    'This wait was added to isolate the exact point when the ie object was disconneecting
    Application.Wait Time + TimeSerial(0, 0, 10)
    'return text from google page
    MyStr = IE.document.body.innerText
    Sheet3.Range("A2") = MyStr
    Set IE = Nothing
End Sub
Another code that gives me an unspecified error is below:

Sub MoveInnerHTMLtoSheet3()

    Dim URL As String
    Dim IE As InternetExplorer
    Dim HTMLdoc As HTMLDocument
    Dim TDelements As IHTMLElementCollection
    Dim TDelement As HTMLTableCell
    Dim r As Long
    'Saved from www vbaexpress com/forum/forumdisplay.php?f=17
    URL = ""
    Set IE = New InternetExplorer
    With IE
        .navigate URL
        .Visible = True
        'Wait for page to load
        While .Busy: DoEvents: Wend
        Set HTMLdoc = .document
    End With
'    Set TDelements = HTMLdoc.getElementsByTagName("TD")
    Sheet3.Range("A2") = HTMLdoc
    Set IE = Nothing
End Sub
Thanks for any advice you can offer.......


I'm trying to work out a macro to exit a workbook without saving that is open on its own webpage in internet explorer. I’ve managed to work out how to do it if I’m working in excel but I can not get the web page to close. Just to make things easier I only need to close the selected page and not all web pages I have open. Does anyone know if/how this can be done?.


I am developing a set of workbooks for publishing on the web. On a normal computer the two workbooks work fine. links.xls opens formulae.xls and runs its macros fine.

Once I open the files inside internet explorer, the files are linked to the same position, I start getting a whole host of errors.

Application.displayalerts = false
This no longer works, gets an error on method 'Application.displayalerts', so I commented this out. Then

tempStr = currentwkb.Path & "formulae.xls" 
MsgBox tempStr 
Set tempWork = Workbooks.Open(tempStr) 

If you like these VB formatting tags please consider sponsoring the author in support of injured Royal Marines
The first two files work fine and reports that the path and filename are what I expect. Then the Workbooks.Open(tempStr) method has the same sort of error as the first error. In that it says:

Method 'Open' on object Workbooks failed.

Is this some sort of problem with excel having trouble running macros from inside an internet exporer window.

This is wrecking my brain so any help greatly appreciated.

No luck finding an answer? You could always try Google.