How do I clear or remove a JAVASCRIPT Alert message box in the InternetExplorer.Application Object?

Odd Job 007

New Member
Joined
Apr 11, 2016
Messages
2
Hi I am relatively new to using the VB language and I’ve run into a slight hurdle. I’ve searched this site and others for a solution but I can’t find an answer that works.

I am using VBA to login to a private (work) intranet page and then process data within the page. I can’t edit the page script on the server side so everything has to be done within VBA and Excel.
After the user logs into the site and submits the form, the new page shows a JAVASCRIPT Alert message. This is a popup within the current window and not a new window. (This is the hurdle)

Is there a way that I can prevent this Alert message box from loading, however the alert appears prior to the rest of the page and readyState doesn’t pass 3. The alert requires the user to click “Okay” to proceed, however the program hangs. Macro execution is suspended until I manually click the <kbd>OK</kbd> button on the pop-up.

I’ve tried the Sendkey procedure, however his is really unpredictable. Further to this, I want the IE load to be hidden with .Visible = False so the Sendkeys doesn’t work (as far as I know).
I have attempted to suppress all popup messages with the IE.Silent = True property. However, this does not stop the alert in question from being displayed.

Neither does removing ******* attribute (http://www.mrexcel.com/forum/excel-...lose-internet-explorer-message-box-popup.html ) This doesn't work

Opening another instance of excel just before clicking submit and run code in the new excel to close the pop up box and close it (VBA Express : Excel - Handling dialog boxes in IE automation) doesn't seem to work for me.

I think one solution is to Set IEDoc = .document then edit out the script alert and then somehow reload the page with the edited script but I’m unsure how to do this.

Please help


This part of the source code


****** http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Record</title>
****** name="GENERATOR" content="Microsoft FrontPage 3.0">


******** language="JavaScript">
function NAME_IT() {************('help1.htm','EANITHING','toolbar=no,location=no,directories=no,status=yes,menubar=no,resizable=yes,copyhistory=no,scrollbars=no,width=350,height=500,top=90,left=480');
}
*********>

******** language="JavaScript">
alert ("Note:- The Record Has Been Executed")
*********>

Here's part of my code

Set IE = CreateObject("internetexplorer.application")

With IE
Loaded = False
.AddressBar = False
.StatusBar = False
.MenuBar = False
.Toolbar = 0
.Visible = False
.Silent = True
.Navigate UrlPage
On Error Resume Next

If Err.Number <> 0 Then 'Check if the ojbect was created.
MsgBox "Sorry, there was a problem loading the database", vbCritical, "Internet Explorer Error"
Exit Function
End If

Do While .Busy: DoEvents: Loop
Do Until .readyState = READYSTATE_COMPLETE: DoEvents: Loop

Set IEDoc = .document

If Not .getElementById("txtUser") Is Nothing Then
.document.getElementById("txtUser").Value = Username ' enter username
.document.getElementById("txtPassword").Value = Password ' enter Password
.document.forms(0).submit ' click submit
End If

cTime = Now + TimeValue("00:00:05")
Do Until (.readyState = 4 And Not .Busy) Or Loaded = True
If Now < cTime Then
DoEvents
Else
If .readyState = 3 Then 'clear alert box and proceed
Set IEDoc = .document ' look at the document returned
‘These are what Ive tried but failed to get to work
For Each TableElement In IEDoc.getElementsByTagName("Script")
With IEDoc.getElementsByTagName("Script")(2)
MyScript = IEDoc.Scripts(2).Text
'MyScript = .document.Script.Text
MyScript = Replace(MyScript, "alert", "//alert", 1, 76)
Call IEDoc.document.parentWindow.execScript(MyScript)
'IEDoc.document.getElementById("Script").removeAttribute ("Alert")
'IEDoc.document.getElementById("clearRelItems").setAttribute "o n C l i c k", "return true"
'temp = "function alert(obj) {document.getElementById('searchText').value=" & Chr(34) & "x" & Chr(34) & "}"
'IE.document.parentWindow.execScript temp
End With
Next TableElement
End If
End If
Loop
Call Data_Process
End With
IE.Quit
Set IE = Nothing
End Function​
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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