How to automate Internet Explorer confirmation box

niteblind

New Member
Joined
Apr 9, 2011
Messages
8
Hi,

Hope you can help with this infuriating issue.

I have a ASP web page one section of which allows me to remove certain data from the page by click a "Close" link. The link is a straight forward HTML affair, and I can automate the clicking of it, however, it comes up with a confirmation box with an OK and Cancel button on it. My code then hands until I click OK.

I had seen a previous post on here advising to change the attribute of the button but that comment related to a Javascript settup which this is not.

The only solutions I can find when I am googling are relating to using Sendkeys, which NEVER works for me. Are there any alternatives?

My Current code is as follows, but always dies as soon as I hit the a.click statement:

Code:
Sub test() 
    Dim appIE As InternetExplorer 
    Dim sURL As String 
    Dim ElementCol As MSHTML.IHTMLElementCollection
 
Application.ScreenUpdating = False 
Set appIE = New InternetExplorer 
sURL = "http:// ..."

With appIE 
  .Navigate sURL 
  .Visible = True 
End With 
                                
Do While appIE.Busy 
Loop 

'NEXT LOOOP NEEDED FOR THE ASP PAGE TO LOAD  PROPERLY                            
timedelay = Now() 
Do Until (Now() > timedelay + TimeValue("00:00:05")) 
Loop 
     
Set ElementCol = appIE.Document.getElementsByTagName("A") 
For Each a In ElementCol 
  Select Case a.ID 
    Case Is = "Close" 
      a.Click 
      Exit For 
  End Select 
Next
I have a similar issue with another automation that needs to download a file, I do not know there either how to click the Open button on te standard IE message box, I assume the solutions will be similar for bother issues???

Any assistance would be greatly appreciated!

niteblind
 
Last edited:

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi Again,

In an effort to help answer this I have nee hunting around and managed to stumble across this, which is a shell script I believe:

Code:
<code>#include <IE.au3>
; Internet Explorer is partly integrated in shell.application
$oShell = ObjCreate("shell.application") ; Get the Windows 

Shell Object
$oShellWindows=$oShell.windows   ; Get the 

collection of open shell Windows
$MyIExplorer=""
for $Window in $oShellWindows    ; Count all existing 

shell windows
  ; Note: Internet Explorer appends a slash to the URL in it's 

window name
  if StringInStr($Window.LocationURL,"http://") then
      $MyIExplorer=$Window
      exitloop
  endif
next
$oForm = _IEGetObjByName ($MyIExplorer, "UploadedFile")
_IEAction($oForm, "click")</code>

The above appears to be doing exactly what I want to do, although I have 2 questions for the gurus amongst you...

1. How do I get this to run form Excel, I realise I will need to use MSHOM as a reference, but the bit at the top "<code>#include <IE.au3>" confuses me.

2. It is possible I would have multiple http windows open, as I have already browsed to the webpage I want to use is there anyway to put the URL into a variable and use that variable in the shell script instead of the "http://" bit?

As a follow on from q2, is there a way to use ActiveWindow to refer to the IE page as it will be in the foreground from what I have seen of the way the Excel IE automation works?

Please, please, please can someone help?

niteblind
</code></pre>
 
Upvote 0
Maybe you can use this VBA code which loops through Shell windows (which include IE windows and tabs) and is equivalent to the last code you posted.
Code:
Sub ShellWindows_Late_binding()

    Dim Shell As Object, IE As Object
    
    Set Shell = CreateObject("Shell.Application")
    For Each IE In Shell.Windows
        Debug.Print TypeName(IE.Document), IE.LocationURL
        If TypeName(IE.Document) = "HTMLDocument" Then
            Debug.Print IE.LocationName, IE.LocationURL
        End If
    Next

End Sub
 
Upvote 0
Hi,

Thanks
for the reply, I am part way there now, so I can now scroll through the IE windows for the page i want to interact with,

What I need to do now, is find the pop up box, now the problem is that it does not appear to have a heading on the box. It just say Microoft Internet explorer and there is then text on the box zsay "Are you sure you want to close"" with and Ok and a Cancel buttton.

Also I do not understand the syntax here:


<code>$oForm = _IEGetObjByName ($MyIExplorer, "UploadedFile")
_IEAction($oForm, "click")</code>


Why the underscore:

<code>_IEGetObjByName?

Can I simply replace it with IE.GetObjbyName??

Cheers
niteblind
</code>
 
Upvote 0
_IEGetObjByName is an AutoIt function (Google it), so you need to download and install the AutoIt Script to call it.

"Can I simply replace it with IE.GetObjbyName?"

No, because IE doesn't have a method called GetObjbyName.

Are you sure this pop-up box is an IE window? Maybe it's a Javascript window.
 
Upvote 0
HI,

Fairly certain this is a HTML popup, it si on an ASP page and has the following source code:

HTML:
Close
What is the equivalent standard windows script for dealing with dialog boxes? I found something on dlg but did not really understand what to do with it.

Also, when I was using early binding on the IE script I noticed a declaration option of MSHTML.HTMLDialog can this be used to interact with a pop up dialog box? If so how would I use this?

Finally I hope, I eanted to change the code above that was provide in reply from late binding to early binding, how would I decalre the IE As Object? Sorr if this may seem silly but I am trying to understand what the IE.XXX is so I can try and work with it, I am a little green on certain things here :)

Cheers for all the help though
niteblind
 
Upvote 0
The HTML you posted just says 'Close' so I don't know what type of pop-up box it is. Without knowing the URL of the web page I can't help further.

HTMLDialog has a Close method and other methods - see MSDN. Maybe you can use that.

Early binding of the IE classes is:

Dim IE As InternetExplorer

with a reference to MS Internet Controls in your VBA project.
 
Upvote 0
If this is an ASP page then it might not be something on the 'client' side that's generating this message/pop-up.

Sounds to me more like something server side, where I'm sure there is some way to make this sort of prompt appear when deleting/removing data.

If it is something on the server you aren't going to see it in the HTML of the page, though you might see indications/hints.

Anyway, as Johnw says, without a URL it's hard to help.:)
 
Upvote 0
Hi,

I am getting the feeling it may be server side. I user found using a DOM inspector that there is some Javascript around this link, but it does not seem to be dealing with the button, more with the layout of the text/info on the screen, which is mainly coming from a database.

Is there really no easy way to control pop up windows through excel? Surely if the pop up is coming up in internet explorer it will be subject to the shell?

Does anyone know of a good and portable DOM viewer for IE? Works IT restrictions are causing me grief using the DOM inspector in Firefox and someone made the sugesstion that as an ASP page the box may be coming in after a reload of the page so to speak and that it may be viewable in the DOM to control.

Also is there a good place that actually explains what options are available in say the Internet explorer reference library as well as how to actually use them? MSDN say it is X but then not actually how to use them if you are a novice (at least what I have found so far doesnt)

Cheers.
Andy
 
Upvote 0
Andy

I usually just use the built-in Developer Tools in IE (F12), nothing to install and I'm not even sure a lot of people know about it.

Mind you I don't think any sort of DOM viewer will help with server side stuff, and I can't see how it would help with this pop-up/messge.

It doesn't sound like a reload of the page, to me anyway, it sounds more like a server request/wait/reponse thing.

I don't know of any 'tutorial' on this sort of thing but you'll probably find plenty of stuff covering the basics.

That's probably because it's an almost impossible topic to cover with all the technolgies involved and how they are going to be used.

The MSDN reference library is what it says it is.

Why not try looking through it for specific information?

That might not be ideal but it should help and you never know you might learn new things.
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,122
Members
452,381
Latest member
Nova88

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