Move to another tab on webpage in internet explorer using vba

K1600

Board Regular
Joined
Oct 20, 2017
Messages
166
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.
 

Some videos you may like

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

K1600

Board Regular
Joined
Oct 20, 2017
Messages
166
This is the full view of the DOM Explorer if it helps.
 

Attachments

  • Picture1.png
    Picture1.png
    65.5 KB · Views: 6

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,712
Search for the "Single" link, maybe like this:
VBA Code:
Dim i As Long
Dim link As Object
Set link = Nothing
i = 0
While i < ie.Document.links.length And link Is Nothing
    If ie.Document.links(i).innerText = "Single" Then Set link = ie.Document.links(i)
    i = i + 1
Wend
If Not link Is Nothing Then
    link.click
Else
    MsgBox "Single link not found"
End If
 

K1600

Board Regular
Joined
Oct 20, 2017
Messages
166
Search for the "Single" link, maybe like this:
VBA Code:
Dim i As Long
Dim link As Object
Set link = Nothing
i = 0
While i < ie.Document.links.length And link Is Nothing
    If ie.Document.links(i).innerText = "Single" Then Set link = ie.Document.links(i)
    i = i + 1
Wend
If Not link Is Nothing Then
    link.click
Else
    MsgBox "Single link not found"
End If
Thanks. That has given me the web address that I was trying to point it to but it doesn't work for some reason. When I click on the "Single" tab it changes to the correct view below it but when I use the link it's just greyed out below it.

I've attached two screenshots showing what I get.
 

Attachments

  • Correct.png
    Correct.png
    5.6 KB · Views: 3
  • Incorrect.png
    Incorrect.png
    4.2 KB · Views: 3

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,712

ADVERTISEMENT

Does the anchor element or its parent elements have any events? If so you'll need to emulate the event with dispatchEvent or FireEvent.
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,712

ADVERTISEMENT

In your browser's DOM Inspector, e.g. Firefox it shows "event" next to the element:
1611699888214.png
 

K1600

Board Regular
Joined
Oct 20, 2017
Messages
166
I've just stepped through it again and if it gets the link from your code then the page shows correctly, yet if I take the address and add it into the code separately, I get the greyed out sections.
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,712
I don't think so, if I have looked in the right place that is! This is what I get.
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).
 

Watch MrExcel Video

Forum statistics

Threads
1,127,405
Messages
5,624,574
Members
416,036
Latest member
eloisa manzanarez

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
Top