Move to another tab on webpage in internet explorer using vba

K1600

Board Regular
Joined
Oct 20, 2017
Messages
181
I am trying to automate using a webpage with excel. I have managed to login to the page and select the page I need to complete some fields on however I am stuck as I can't work out how to move to another tab. On the page I need there is an area with 6 tabs in it, I want to move to a tab named "Single" but can't work out how to reference it. If I 'Inspect Element' it shows <span>Single</span>.

Can anyone advise how I need to refer to the tab to be able to select it. I'm currently using the below code which works for the rest but just not the tab:

VBA Code:
        With ie

            .AddressBar = 0
            .StatusBar = 0
            .Toolbar = 0
            .Visible = True
            .Navigate sURL1

        Do Until Not .Busy And .ReadyState = 4
        DoEvents
        Loop

'Login to site
            .Document.all("login-email").Value = WebUN
            .Document.all("login-password").Value = WebPass
            Application.Wait Now + TimeSerial(0, 0, 2)
    
        End With
    
        Do Until Not ie.Busy
        DoEvents
        Loop
    
        ie.Document.all("login-messenger").Click    'Press 'Login' button
        'ie.Document.all("nav-sendmessage").Click
        ie.Navigate sURL2            'Selects 'send' page
                    '<<<<<<<<< Single tab needs selecting here
        ie.Document.all("quicksendnumber").Value = "TEST"   
        ie.Document.all("message-body").Value = "TEST"

        Do Until Not ie.Busy
        DoEvents
        Loop

Thanks in advance.
 
Have you checked all the parent elements? Click the parent elements in turn along the bottom of the pane (where "span" is currently highlighted in blue).
The "a" has this:
1611702256002.png


"form#sendtextmessage" has this:
1611702319311.png

"main#canvas" has this:
1611702256002.png

and "body#page-send" has this:
1611702431431.png
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
So the anchor element (the "a" tag) has a click event. Emulate the click event by replacing my link.click with this code:
VBA Code:
Dim clickEvent As Object
Set clickEvent = ie.document.createEvent("HTMLEvents")
clickEvent.initEvent "click", True, False
'link.click   'might need this as well
link.dispatchEvent clickEvent
I don't know what sURL2 is, but also add this code after the ie.Navigate sURL2 'Selects 'send' page in your code:
VBA Code:
    While ie.Busy Or ie.readyState <> 4: DoEvents: Wend

Edit: you might need the change event as well as or instead of the click event, therefore (leave as shown below, or comment out one of the dispatchEvents)
VBA Code:
Dim clickEvent As Object
Dim changeEvent As Object
Set clickEvent = ie.document.createEvent("HTMLEvents")
clickEvent.initEvent "click", True, False 
Set changeEvent = ie.document.createEvent("HTMLEvents")
changeEvent.initEvent "change", True, False 
'link.Click   'might need this as well
link.dispatchEvent clickEvent
DoEvents
link.dispatchEvent changeEvent
 
Last edited:
Upvote 0
So the anchor element (the "a" tag) has a click event. Emulate the click event by replacing my link.click with this code:
VBA Code:
Dim clickEvent As Object
Set clickEvent = ie.document.createEvent("HTMLEvents")
clickEvent.initEvent "click", True, False
'link.click   'might need this as well
link.dispatchEvent clickEvent
I don't know what sURL2 is, but also add this code after the ie.Navigate sURL2 'Selects 'send' page in your code:
VBA Code:
    While ie.Busy Or ie.readyState <> 4: DoEvents: Wend

Edit: you might need the change event as well as or instead of the click event, therefore (leave as shown below, or comment out one of the dispatchEvents)
VBA Code:
Dim clickEvent As Object
Dim changeEvent As Object
Set clickEvent = ie.document.createEvent("HTMLEvents")
clickEvent.initEvent "click", True, False
Set changeEvent = ie.document.createEvent("HTMLEvents")
changeEvent.initEvent "change", True, False
'link.Click   'might need this as well
link.dispatchEvent clickEvent
DoEvents
link.dispatchEvent changeEvent
That seems to have done the trick, thank you.

The sURL2 is just the 'send messages' page that I need but it was easier to navigate to it than to click through a few pages to get to it. I have added the While line in there too, I had missed that one.

Thanks again :)
 
Upvote 0

Forum statistics

Threads
1,223,634
Messages
6,173,477
Members
452,516
Latest member
archcalx

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