Using VBA to Close Internet Explorer Message Box Popup

akrobrat

New Member
Joined
Nov 2, 2009
Messages
3
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).

Problem:
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...
Code:
IE.Document.getelementbyid("clearRelItems").click()
... 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:
<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
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I hate doing this but I would think you could use the application.sendkeys command to send a carraige return to the popup.
 
Upvote 0
@Blade Hunter: Thanks for the response. I have tried using Application.Sendkeys, but the code comes to a complete halt and doesn't get to the Sendkeys statement after the IE Message Box pops up. It waits around for human intervention before proceeding with the code. How can I overcome this?

Thanks again.
 
Upvote 0
Just in case, the code on the HTML page has the following line for the button...
HTML:
<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).
I see the forum software has modifed your HTML - the '*******' in the above HTML is meant to be 'o n C l i c k', without the spaces. If you're allowed to, you could try removing the o n C l i c k attribute and/or setting your own o n C l i c k attribute, so that the Javascript confirmation window doesn't appear. Like this, maybe:
Code:
IE.Document.getElementById("clearRelItems").removeAttribute ("o n C l i c k")
IE.Document.getElementById("clearRelItems").setAttribute "o n C l i c k", "return true"
That code is untested and the syntax might be wrong - have a play around. Search for HTMLInputButtonElement for more properties and methods of the Input button.
Code:
    Dim ib As HTMLInputButtonElement
    ib.o n C l i c k = ""  'remove spaces
Might work instead of removing/setting the attribute. Note - there should be no spaces in o n C l i c k in VBA and HTML code!
 
Upvote 0
John W, your suggestion to change the attribute in the document rather than fighting the popup confirmation window worked. :) I was even able to use the removeAttribute method to get rid of some of the ReadOnly fields to process document faster.

I didn't test the HTMLInputButtonElement, but it may cmoe in handy for someone that runs into this issue in the future.

Thank you very much!
 
Upvote 0
Hi Folks,

I found this info very useful... i have been searching for this long time...

but my situation is little different now....

the html code for the button has been formed using

Code:
SPAN

tag in that they are using

Code:
A

tag with on click event.

i am able to click the tag... but the message box is still displayed..

i tried setAttribute and removeAttribute but no help... still the message box appears...

i am not sure i can use the HTMLInputButtonElement, since my html button is not exactly an input button.

kindly help me on this......

Thanks
 
Last edited:
Upvote 0
I see the forum software has modifed your HTML - the '*******' in the above HTML is meant to be 'o n C l i c k', without the spaces. If you're allowed to, you could try removing the o n C l i c k attribute and/or setting your own o n C l i c k attribute, so that the Javascript confirmation window doesn't appear. Like this, maybe:
Code:
IE.Document.getElementById("clearRelItems").removeAttribute ("o n C l i c k")
IE.Document.getElementById("clearRelItems").setAttribute "o n C l i c k", "return true"
That code is untested and the syntax might be wrong - have a play around. Search for HTMLInputButtonElement for more properties and methods of the Input button.
Code:
    Dim ib As HTMLInputButtonElement
    ib.o n C l i c k = ""  'remove spaces
Might work instead of removing/setting the attribute. Note - there should be no spaces in o n C l i c k in VBA and HTML code!
The Attribute idea worked for me in the past but I'm stuck now.
INPUT style="WIDTH: 100px" id= StatusBar_btnDelete class=MyButton *******="DeleteBtnClicked(); return false;" value=Delete type=submit name= StatusBar$btnDelete
Using "Return True" doesn't cut it. I tried a bunch of variations. DeleteBtnClicked gives me a Yes/Cancel prompt. Is there a way to rewrite it so that I'm submitting an Ok respose?
Or is there a way to sendkeys to the prompt without using sendkeys since that doesn't work?
 
Upvote 0
The Attribute idea worked for me in the past but I'm stuck now.
INPUT style="WIDTH: 100px" id= StatusBar_btnDelete class=MyButton *******="DeleteBtnClicked(); return false;" value=Delete type=submit name= StatusBar$btnDelete
Using "Return True" doesn't cut it. I tried a bunch of variations. DeleteBtnClicked gives me a Yes/Cancel prompt. Is there a way to rewrite it so that I'm submitting an Ok respose?
Or is there a way to sendkeys to the prompt without using sendkeys since that doesn't work?


Hi,

I am stack with the same issue.
When I click Download button through macro,Download popup comes which need manual click.Here,I want to avoid it and do automatically through macro and download excel file on respective path.

Plz someone help me on this.

Thank you in advance.
 
Upvote 0

Forum statistics

Threads
1,223,690
Messages
6,173,847
Members
452,535
Latest member
berdex

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top