Handling IE pop-up with VBA

Viewed 2611

I have an Excel VBA macro that interacts with an intranet site through Internet Explorer to loop through a list of customers, open the customers profile, update a field and save the changes.

The problem I am running into is that when I save the changes to the customers profile there is a pop-up window in the web application asking me to confirm the changes to their profile and i can't figure out how to programatically click the "OK" in the pop-up. When I click the save button, the javascript executes a function call for submitting the changes.

Send keys won't work because the code will not execute the next line until the pop-up is confirmed. i tried some other solutions mentioned and couldn't get them to work correctly (the javascript parts are new to me).

Any help in figuring out how to programatically click "OK" to let my code run in peace would be greatly appreciated.

VBA code:

    'pulling up edit user profile link
    s = objIE.document.getElementsByTagName("a")(4).href
    objIE.navigate s

    'wait here a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop

  'Adding value to customers profile and saving changes
    objIE.document.all.Item("Contact_Id").Value = Sheets("List").Range("c" & n).Value
    objIE.document.all.Item("submitBn").Click

    'wait here a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop

Java script function the submit button is calling:

function doNextPage() {
if (checkFormInputForEnglish(document.editProfileForm)) {
    if(validateForm()){
        if(confirm("Do\x20you\x20want\x20to\x20submit\x20the\x20changes\x3F")) {
            document.editProfileForm.submitBn.disabled = true;
            document.editProfileForm.submit();
1 Answers

Using VBA,

focus the submit button by objIE.document.all.Item("submitBn").Focus

And Then use SendKeys "~" to Click the button.

So here VBA won't be engaged. Now, Detect the (HTML)popup by checking if the HTML popup code is Visible/Exist

Related