Close Window
Free Ebook
Get Your Free Excel
Top 15 Excel Tutorials from
Instant Access!

Using Vba To Close Internet Explorer Message Box Popup

Hello, everyone! First time caller, long time listener.

I'm automating a number of weekly reports by using VBA to populate data from an intranet site (via Internet Explorer) into Excel 2003. I am an intermediate user and just ran into something to which I cannot find a solution online.

Current Process:
(1) Navigate to site (2) Use Regular Expressions to extract first set of data into Excel (3) Make changes to page (via buttons and input fields).

I've got a handle on nearly everything but in Step (3), IE has a MessageBox popup that asks for confirmation before I deleted some data. That is, I click on a button to clear the items...


... and then the Message Box appears, with options "OK" and "Cancel", and I need to hit "OK". Since it's technically not a New Window, I don't think I need to worry about Shell scripts. I can't seem to set any code after this because the Message Box forces user input before continuing.

Just in case, the code on the HTML page has the following line for the button...
HTML Code:

<INPUT TYPE=BUTTON NAME=clearRelItems ID=clearRelItems VALUE="Clear List" *******="add_rel_items_to_box(0);">

... but I can't touch any of the JavaScript that's included (company no-no).

What are my options? Can I use keystrokes to mimic pushing the "OK" button? Would I set a timer that could keep checking to see if the Message Box has popped up and to hit "OK"? Thanks in advance for any insight!

- Angelo

Free Excel Courses

Similar Excel Tutorials

I'll show you how to create a message box popup window in Excel that contains text on multiple lines.  This allows ...

Connect and login to a website using a macro in Excel. This allows you to open a website and automatically login wi ...

How to close an Excel workbook using VBA and macros, including how to save the file before you close it or discard ...

How to open a website in the browser from Excel using a Macro and VBA. This is the same as following a link or clic ...

Helpful Excel Macros

- This is a very simple Message Box, pop-up window, macro for Excel that illustrates how to put new lines, the same thi

- Add data validation input messages to cells in Excel with this free Excel macro. These messages appear when a specific

- This macro will display a message box in excel when a cell reaches a certain value or contains certain text. This means

- This free Excel macro illustrates all of the possible parameters and arguments that you can include in the PrintOut Meth

- This Excel Macro allows you to save a specific worksheet within the Excel Workbook to its own new file. You will be a

Similar Topics

I'm having a problem in a workbook with several ActiveX command buttons. I had been using the form control buttons to run macros, but the boss wanted each button to have it's own, different color. So I removed the form control buttons and created new ActiveX command buttons. I got into the button properties and set the background colors. I added the _Click code to run the macros when the user clicked the buttons.

All of the buttons were working fine. Then I saved and closed the workbook and went to lunch. Now when I open the workbook, the buttons don't work! When I click them nothing happens. They appear frozen. They don't even seem to click. No error message. Nothing.

If I right-click the button in Design Mode and select Properties, I get sheet properties not the button properties. I can't seem to locate the command button properties any longer. I still see the button name "cmdButtonGetInfo" and "=EMBED("Forms.CommandButton.1","") in the name box and formula bar. The odd thing is if I create a new button it works fine until I save and close the file. When I reopen the file none of the buttons work.

It's like the buttons are being disabled when I close or open the file. Any suggestions?

I'm trying to use VBA to go to a website that requires a User Name, Password, and a Submit Button.

So far I can get everything to work besides the Submit part. The code runs without errors, but doesn't actually "hit" the submit button on the webpage.

For posting, I removed my actual user name and password and and used the generic " User Name " and " Password " highlighted in blue.

I highlighted another section in green that I took from a previous post hoping it would solve my problem. The link is: /

Here is the code I am using:

Sub GoToWebSiteAndPlayAroundNew()

Dim appIE As Object ' InternetExplorer.Application
Dim URL As String

Set appIE = CreateObject("InternetExplorer.Application")
URL = " / "

With appIE
.navigate URL
.Visible = True

Do While .busy: DoEvents: Loop
Do While .ReadyState 4: DoEvents: Loop

.document.getelementbyid("fUserName").Value = " UserName "
.document.getelementbyid("fPassword").Value = " Password "

End With

On Error Resume Next
x = 0
For Each mitem In IE.document.all
mitem.Value = "x"
x = x + 1

x = 0
For Each mitem In IE.document.all
If x = "Submit" Then
Exit For
End If


End Sub

I run a small business. I want to start keeping track of inventory using a barcode system.

I know Excel "ok", but I don't know programming.'

I'd like to be able to do something very simple (for now)...

For example...if I had PRODUCT / CODE / INV VALUE

A - CODE A - 5
B - CODE B - 11
C - CODE C - 14

I would want to be able to click a button (or scan a code for) : ADD +1 or REMOVE -1

...then scan the barcode on the product (A) and have it add or remove one, respectively. So, if the row for A is:

A - CODE A - 5

I choose "ADD" (with a button or scan code), then scan the barcode, and the spreadsheet automatically finds the code in the sheet, and changes the corresponding inventory value:

A - CODE A - 6

Does that make sense? How might I go about doing that?

I added a print button to my userform


Private Sub btn1_Click()
End Sub

This prints out the userform as I would like, however it autoprints to the default printer and doesn't allow any printing options so I can't select to "print to one page". So as of now it is only printing out half my form and cutting off the rest.

Any suggestions?


i've got the following problem:

I want users to double-click on a row on a protected sheet and then do some code based on the row-number of the clicked cell. I've protected the sheet because it contains a lot of formula's.

When a user double-clicks a row it triggers the code through the Workbook_SheetBeforeDoubleClick event.
After the code is executed Excel shows a message that the cell that was clicked was protected etc etc.

How can I prevent this message from popping up?

I've already tried

application.displaywarnings = false

but that didn't work


I have an excel form, I want my users to be able to open the form, fill in appropriate data, then click the save button. When the button is clicked, the data in the form should be saved to a new file and then the original form should be reset (clear all values) for a new set of data entry. When the data is saved, I want the new excel sheet to be saved to a location specified within the macro so the user doesn't have any options and I want the title of the new file to be the value of one of the cells.

I'm new to macros and would appreciate any help this board can offer. Thanks...

Hi All,

I got the below macro which uses IE and open the URLs. I want to create a userform with listbox with radio button and commandbutton on the same which will help me to connect to each url when I select the same in listbox and click on the commandbutton.

Sub DoBrowse1()
 Dim ie As Object
 Set ie = CreateObject("Internetexplorer.Application")
 ie.Visible = True
 ie.Navigate ""
End Sub

Any suggestions..

Hi Excel experts,
I am working on a worksheet, and would like to have an entire row transferred to another worksheet based upon a certain cell's value.

Having searched through the many solved threads on this site, I attempted to customize some of the code to my worksheet. Not being proficient in Macro/VBA, I failed. I figured I would ask for help, and see if anyone can provide what I am looking for.

Basically, I am attempting to construct a "work in process" file, and would like all completed work to be deleted from the work in process sheet, and transferred to a sheet that contains a running list of all work completed.

Attached is an example of what I am working on. I would like Column Q (Status) to determine if a row can be moved to a sheet that contains the list of all work completed, and eliminated from the original sheet. Once Status is updated to "Complete", it would be helpful to be able to run a macro/click a button that would perform the transfer.

Can anyone assist?


I need the necessity do delete a sequence of sheets in my workbook.
If I use this code:

With ActiveWorkbook
If .Worksheets.Count >= 5 Then
For n = 5 To .Worksheets.Count
Next n
End If
End With

I receive a confirmation message box with this message:

"Data may exist in the sheet(s) selected for deletion. To permanently delete the data, press Delete" [DELETE] [CANCEL]

I wish to delete all sheets without receiving any message.

Is it possible?

Many thanks in advance for your kind support.



I have searched and read all the help files. I find the properties of
an object, I see how I can "lock", "size and move with cells" or "not
move with cells". No matter what I select, the object moves off the
screen, when the user, scrolls to the right of the spreadsheet.

Is there a way to lock the position, let's say, in the upper right
corner and have it stay there?

This would be quite useful for an EXIT button, that I have created,
that will close the program without saving (it's a read-only file.)

Thanks to all the wonderful people here that have been so helpful and
give us their valuable insight and time.


I get the error message "reference is not valid" each time I open my spreadsheet. I get this message three times, and once I am done clicking ok on all three of them, my spreadsheet works just fine. The problem is, I have to send it to a bunch people.

I have a sheet with raw data a sheet with pivot tables a sheet with a dashboard and a simple macro
I don't have any #REF cells either.

Someone has any idea of what could be the problem?



Posted this on the Ozgrid forums, but haven't gotten any help yet, so I thought I'd try here too!

I've been having a strange problem lately. I have a fairly lengthy macro that works perfectly most of the time. Occasionally it will run as expected but as soon as the macro ends, excel becomes unresponsive to mouse-clicks. When I click anywhere (trying to select a cell, or an excel menu item...clicking anywhere in excel) I'll get the a 'ding' system sound and nothing will happen. BUT, if I use the keyboard arrow keys, I can see that the active cell selection moves accordingly. Then it gets really strange - when I have a cell highlighted and press any key to input text, it gets duplicated. So if I press "s' it will input "ss" into the cell, and then when I press enter it will auto-move to the next cell down, but nothing ends up getting saved into the previous cell.

I don't understand what's going on at all. I can't think of anything in my macro that would have these kinds of effects. I've made sure that screenupdating is turned back on at the end of every procedure. If I go into the VBE, I can manually run procedures and they all work fine. The only way I've been able to get back to normal is by force closing excel altogether and re-opening. Any ideas?


Still having trouble, and the same thing is happening with this workbook on two different computers, so I don't think it's a hardware, or OS specific issue. When it gets locked up like this, I can still do anything in the VBE (edits cells, run macros, etc.) with no problems. If I'm in the excel window, I can click alt on the keyboard and the shortcut keys for the menu come up, but I can't go deeper than that by clicking the letter shortcuts, they do nothing. If I use the delete key to delete the contents of a cell, then it gets deleted. But if I type anything else (numbers, letters, or symbols) then it types 2 instances of the key every time, yet when I hit enter, nothing changes in the cell. I also can't really bring focus to the excel window if something else (ie. the VBE) is on top of it, clicking into the excel window just gives the little system 'ding' sound and nothing happens.

If I hit the save button in the VBE (since I can't click anything in the excel window), then it seems to snap out of it and go back to normal. I tried searching for anything simmilar to this and can't find anything...

Any help would be much appreciated. This is driving me nuts!

Using VBA, I am trying to retrieve the contents of the Source of a web page (the same as would appear if you right-clicked on the page and chose "View Source") into a variable so I can work on it in VBA (using InStr, etc.).

The problem is I can use code such as
strHTMLText = ie.Document.body.innerText
strHTMLText = ie.Document.body.outerText
to retrieve the code, but in either case only part, not all, of the source code is captured. I need ALL the code. Is there some kind of code such as ie.Document.body.allText or similar that would perform this function?

Much obliged!


I'd like to be able to copy data from a list of websites into Excel. It would take too long to navigate to do an Excel web query for each site, so is it possible to write a macro that could do that?

Thank you!



I have written a macro and at the end it displays a message "The macro has finished".

I would like this message box to disappear after 2 seconds automatically so that users don't have to press the OK button all the time.

can this happen ?


I have a excel spreedsheet that contain external data. I would like to put a
button in the excel sheet to update the sheet without doing right click and
My user here are very dummies.

Hi All,

I have the below code which deletes all items from a listbox and my excel sheet which is the source for populating that listbox. I am using a option button style for my listbox and the selection style as single .i.e. you can select only one item at one go in the lisbox. I want my macro to delete the selected item from my worksheet .i.e. it's entire row so that it doesn't reflect in my lisbox any more. Below is my code :


Private Sub CommandButton2_Click()
 Dim I As Long
 With ListBox1
 For I = .ListCount - 1 To 0 Step -1
 If .Selected(I) Then
 .RemoveItem I
 Sheets("URL List").Rows(I + 2).EntireRow.Delete
 End If
 Next I
End With
End Sub

Thanks a lot for your help in advance.

Okay, so I tried (for hours) to find a solution to this and have finally gotten frustrated to the point where i think asking here will be my best bet.

Basically I want to export data from excel worksheets to various places on a word document I had. I have created a word template as well as bookmarks for that template, as that seems to be the recommendation for performing such a task with excel.

My problem is ... Now what?

I basically have 1 constant worksheet that contains all my affiliates info (Name, Address etc), which i'd like to use to populate some bookmarks in my word template, and then i have another worksheet for the previous month, indicating sales etc for that affiliate. I intend on adding a new worksheet every month that i would use to create new invoices.

Furthermore, i'd really like to be able to update a new file (or perhaps a new page on the same file) for each company with the use of a button, similar to the one's you'd see in an access form.

Can anyone help? Let me know if you need me to clarify.



Hi everyone, this is my first post here. I consider myself a more advanced Excel user and can navigate my way around fairly well. I've written a spreadsheet and am wondering if there is a way to permit data entry in a cell, contingent upon another cell being populated.

In simple terms, you can't enter data in cell X, until cell "Y" has been populated with something.

Can anyone help with this, because I can't figure it out....

Hi guys,

I was wondering if it is possible to change the color of a command button after it's been clicked?

This is to allow the user to identify which buttons have already been clicked.


Hi all,

I have written some code that when a button is selected will Refresh a Data Query Table and all of it's information. However, I seem to be getting issues, can some one point me in the right direction with the code?


.Sheets("Sheet 1").ListObject.QueryTable.Refresh BackgroundQuery:=False

When I recorded myslef doing this process it looked like this:


Sheets("Sheet 1").Select
Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False

Many thanks!


I have a login form with an Exit button. I want my workbook to close as I click Exit button.


My Cell C3 is a numeric value.....I have set conditional formatting to
make the text red and bold when the number is equal or less than 10,000
is there a way I can make cell E3 display a message when the C3
condition is true?? or if not a message is there a way to make a
message box pop up when my C3 condition of less then or equal to 10,000
is true?

how would I do something like this?

I have a requirement to change the panes in excel.
My excel file will contain more than one tab.
I have to free the first two lines in all the tabs except the first one.
I tried the following code.


ActiveWindow.FreezePanes = True

But in this I have to change the Active Worksheets in VBA, Which I want to avoid.
Is there any method to achieve this without selecting the cells.
Something like

xlsobj.Worksheets(1).Rows("1:2").FreezePanes = True

Hi All,

I've been struggling with this for a while now and can't believe how hard it is!. I've searched on this site and on others to get some clarification but to no avail.

It's pretty simple really. I have a user form which contains a tex box for a user to input the date I want the format to be dd/mm/yyyy but can't find out how to set the format of the text box to this.

Please can someone give me a bit of guidence or link me to a good rescource if missed it in the search.

Thanks in advance.


Related pages

shortcut for merging cellshow do i lock a row in excelsolve equation excelpop up excel calendaraccess mde fileconvert decimals to feet and inchesvb6 open text fileexcel dialernumber combination generator 5 digithow to construct a lorenz curvesquared symbol in excelspeedometer chart in excel 2010how to drag numbers in excel using keyboardvba check boxmultiply on excelhow to countif multiple criteriapca in excelvba error 91excel weighted averagesexcel formula amount in wordsexcel convert number to words chequeleast squares excelhow to prepare payslips formatdoes not equal sign in exceldaily log template excelshift rota calendarwhere is the tick in excelhow to remove header and footer in excelexcel 2003 split cellstaff rota excelexcel comma separatorinsert footnotes in excelfree timesheet calculator with lunchexcel odbc sql queryirr xirrconvert fractions to millimetersvba goalseekhow do i combine two columns in excelico changeradding secondary axis in excel 2013vba color palettegoogle earth utm coordinateslinear trendline equationdelete row vbaexcel formula percentage formattimesheet with lunch calculatorselect random numbers in excelhow to get rid of leading zeros in excelweight stone to kg chartexcel function percentilefillable bracketworkdays per monthexcel vba clear autofilterruntime error subscript out of range 9excel formula with multiple conditionsvba drop downcomma separator excelinstalling solver in excelvba code dictionaryunlock workbookexcel color schemeshow do you calculate compound interest in excelremove spaces from cell in exceldelete duplicate cellsunable to create activex objecthow to nest functions in excelhow to merge multiple cells in excel without losing datahow to sum percentages in excelvlookup with concatenateexcel decimal places formulafibonacci excelcorrelation calculation excelupdating pivot tablesexcel thisworkbookvlookup with isnaexcel sheet for quantity surveying