Internet Explorer Script, pop out box close

Swifty87

New Member
Joined
Oct 23, 2019
Messages
18
Hey All,

Looking for some help that i am going a bit mad trying to figure out!! I am writing a VBA that needs to open a report via a Internet explorer Webpage. I am having some success but stuck when a pop up box appears that i need to close. I have been using the IE DOM Explorer to get the ID of the buttons i need to press and input data etc. but i can't get it to close a pop up box See image attached. I think it is because it has no ID called out struggling to figure out how to do this, thinking it might be an "A" Tag"? hyper link.

The 'Select Element' within IE shows it as the following

<IMG tabIndex=-1 class=urPWButtonImage border=0 src="http://bhbh1as13.ent.bhicorp.com:8013/sap/public/bc/ur/nw5/1x1.gif" action="close">

the VBA i have written so far is as follows, area i have an issue with is when i try to click on "WDW02-spr" have tried "WDW02-Close" as well

VBA Code:
Sub SearchBot()
 
    'dimension (declare or set aside memory for) our variables
    Dim objIE As InternetExplorer
    Dim aEle As HTMLLinkElement
    Dim y As Integer
    Dim result As String
 
    'initiating a new instance of Internet Explorer and asigning it to objIE
    Set objIE = New InternetExplorer
 
    'make IE browser visible (False would allow IE to run in the background)
    objIE.Visible = True
 
    'navigate IE to this web page
    objIE.navigate "http://bhbh1as13.ent.bhicorp.com:8013/sap/bc/webdynpro/sap/zbhzoob_addflds_mntn?sap-language=EN"
 
    'wait here a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
 
    'ORDERNUMBER AS IN cell "A2" value
    objIE.document.getElementById("WD30").Value = _
      Sheets("Sheet1").Range("A2").Value
      '& " in " & Sheets("Sheet1").Range("C1").Value
      
       'PLANT NUMBER WRITTEN IN F1
    objIE.document.getElementById("WD6F").Value = _
      Sheets("Sheet1").Range("F1").Value
      
         objIE.document.getElementById("WD30-btn").Click
            'wait again for the browser
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
    
    
   [B] 'help issue i am having BELOW ************
        objIE.document.getElementById("WDW02-spr").Click
'wait again for the browser
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop[/B]
 
    'click the 'go' button
    objIE.document.getElementById("WDDC").Click
    
 
    'wait again for the browser
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
    
    End Sub

Any and all help greatly appreciated :)
 

Attachments

  • IE Help.JPG
    IE Help.JPG
    123.8 KB · Views: 25

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
in your image, it is *indeed* an image, as it shows up as an <img> tag. the *class* attribute of HTML tags, more than likely, cannot be accessed like other DOM elements can be, and according to the ever so popular basic tutorial website, the attribute is mostly associated with CSS stylings. you can indeed click many elements on a webpage by using VBA code, but I seriously doubt you can click on a section of an image. if the dialog box is indeed an image that belongs to an actual class, then you won't be able to do it, more than likely.

you should also note, that as the future roles on, more and more business websites are getting better at detecting automation on webpage that is coming from 3rd party applications like ms office products. If this webpages you're accessing is your own business's, then that's probably fine. but if it's a client's website or another business's website, your methods might not work at some point in the future. just an FYI there. most companies are not nearly as smart as players like google and apple when it comes to detecting outside automation.
 
Upvote 0
Hey Adam,

Really appreciate the response :) the website is for our own business. ok so ruling out the IMG link. Would it be possible to select the 'A' Tag instead i have had a try with this using to following, but to no joy

VBA Code:
        objIE.document.getElementById("WD30-btn").Click
            'wait again for the browser
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop

See image for potential alternate route, and below for HTML when i select that element

VBA Code:
<A ondragstart="var e=window.event;e.cancelBubble=true;e.returnValue=false;return false;" tabIndex=0 id=WD01FD title="Cancel " class="lsButton lsTbarBtnStd urBtnHeightIE11 urNoUserSelect urBtnRadius urBtnStd" style="TEXT-ALIGN: center" href="javascript:void(0);" ti="0" lsevents="{Press:[{ResponseData:'delta',ClientAction:'submit'},{}]}" lsdata="{0:'Cancel',4:'Cancel'}" ct="B">
<SPAN class="lsButton__text urBtnCntTxt">Cancel</SPAN></A>

Again any and all help appreciated
 

Attachments

  • IE Help 2.JPG
    IE Help 2.JPG
    90.1 KB · Views: 11
Upvote 0
I have no clue why you're doing this:
VBA Code:
        objIE.document.getElementById("WD30-btn").Click
nowhere in the HTML that posted or in the image you posted does the string "WD30-btn" appear. and this:
VBA Code:
<A ondragstart="var e=window.event;e.cancelBubble=true;e.returnValue=false;return false;" tabIndex=0 id=WD01FD title="Cancel " class="lsButton lsTbarBtnStd urBtnHeightIE11 urNoUserSelect urBtnRadius urBtnStd" style="TEXT-ALIGN: center" href="javascript:void(0);" ti="0" lsevents="{Press:[{ResponseData:'delta',ClientAction:'submit'},{}]}" lsdata="{0:'Cancel',4:'Cancel'}" ct="B">
<SPAN class="lsButton__text urBtnCntTxt">Cancel</SPAN></A>
doesn't really mean anything. You have to realize that the actual "cancel button" that you're looking at is not a real button element, but rather a *span* with a *class* attribute attached to it. I highly doubt you can run a click operation on a span element. I'm not an expert in your issue by any means, but if you want more information about other things involved in this problem of yours, check out the purpose of the ondragstart() event, and details about the <span> element. and the purpose of using a void in javascript. it's also noteworthy for you to realize that the *ondragstart* start event appears inside the <td> element in the HTML markup, which pretty much suggests that the actual *columns of data* you see in the box in the image, can be clicked on and moved around. I'm headed off to bed. If you need further follow up, and no one else gets back to you, I'll take a look again tomorrow night. I'm gone all day tomorrow in the morning and afternoon.
 
Upvote 0
Thanks Adam, I will run through the links you have sent. I am very much just learning via google searches and youtube tutorials, therefor i am quite sure some of the things i am doing will appear idiotic to say the least :)

Many thanks,
G
 
Upvote 0
Thanks Adam, I will run through the links you have sent. I am very much just learning via google searches and youtube tutorials, therefor i am quite sure some of the things i am doing will appear idiotic to say the least :)
I learn plenty from online tutorials myself, most recently being those regarding the Python programming language. If you're in a learning phase, there's no question that's *idiotic*. Regarding Excel, ask away. No shame in that. :)
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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