VBA Internet Automation

VBAlearner5

New Member
Joined
Jan 25, 2015
Messages
4
Hi,

I am trying to use VBA to log into a website and then complete several actions.

So far I managed to log into the page, but I am unable to then click a button/link in a sub-menu.

I would be really grateful for any advice on how to execute the link in this sub-menu.

Thanks a lot!


My VBA code is:

Code:
    Dim ie As Object
    Dim x As Object
     
    Set ie = CreateObject("InternetExplorer.Application")
    ie.navigate "https://www.intraship.de/intraship/jsp/SessionCtrl.jsp"
    ie.Visible = True
     
    Do While ie.Busy And Not ie.ReadyState = 4
        DoEvents
    Loop
     
    DoEvents
    
    ie.Document.all.Item("jTFName").Value = "XXX"
    ie.Document.all.Item("jPFPassword").Value = "XXX"
 


    Set x = ie.Document.getElementsByName("jBtnOK")
    x(0).Click
 
 
    Do While ie.Busy
    Loop
        
     
    ie.Document.getElementById("jBtnDispatchExpress").Click
    ie.Document.getElementById("jBtnNewExpress").Click


Everything works fine until this part:

Code:
    ie.Document.getElementById("jBtnDispatchExpress").Click
    ie.Document.getElementById("jBtnNewExpress").Click


The relevant html code for the part that is not working is:

HTML:
			  <div class="row">			  	<div class="column_1"><img src="./images/pfeilrot1.gif"></div>			  	<div class="column_2">			  		<a href="javascript:openSubMenu( 'Top', 'DispatchExpressSub' );highlight( 'Top', 'jBtnDispatchExpress', 'Main' );" class="hyperRef">			  			<span id="jBtnDispatchExpress" class="divButtonStyle">Versandabwicklung<br>Express</span>			  		</a>			  	</div>			  </div>									  <div class="row" id="DispatchExpressSub" style="display:none;">						  	<div class="column_1"> </div>			  	<div class="column_2">		  			<div class="subRow">		  				<div class="subColumn_1""><img src="./images/pfeilrot1.gif"></div>		  				<div class="subColumn_2">			  				  					<a href="HXEmLJLhp7+gftPawiAG+MRpBZ+7wUt_kidM02RsbuRmA3e4QkIK_0L7c_h22sCN08+z8LFiv9+aognMt7GJI5Uv3YvN5WvOgw+P1QnXDiNHwB2DBcG6BnwejPyMyzrXZTCWkdZif4oCLP6UCwVZog--.jsp?IS=1&jBtnNewExpress=1" class="hyperRef" *******="highlight2( 'Top', 'jBtnNewExpress', 'Main' );" target="Body">			  					<span id="jBtnNewExpress" class="subButtonStyle">Neuer Auftrag</span>			  				</a>			  			</div>		  			</div>
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try:
Code:
ie.Document.getElementById("jBtnDispatchExpress").parentElement.Click 
ie.Document.getElementById("jBtnNewExpress").parentElement.Click
You might need parentElement.Focus before each Click.

Also, it is easier to write code for web pages if you use the MS HTML Object Library and use variables of the appropriate MSHTML type to reference the intermediate elements rather than trying to do everything in one statement as you are doing.
 
Upvote 0
Thank you very much for your response.

Unfortunately, it did not work either. I am getting a runtime error 91 "Object variable or With block variable not set"

I am not sure whether this is relevant (as I have hardly any VBA experience), but the submenu button/link I am trying to access is in a sidebar. The HTML code, which I pasted above is not from the main form source code; it is from the source code that you get only when you right-click on the side-menu.

Also, when I tried to click the first button, it did not work with the ie.document.click method either. That's why I used the "set X" method. But this method does not work with the side menu link, either.

I would appreciate any further advice. Thanks a lot!
 
Upvote 0
The HTML code, which I pasted above is not from the main form source code; it is from the source code that you get only when you right-click on the side-menu
Which suggests a frame/iframe, in which case the VBA code needs to access the HTMLDocument within the relevant frame. Search this forum for code which accesses HTML within a frame.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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