2

Thank you in advance for any assistance that can be offered. I am trying to activate a link with Excel VBA to change the view of the data presented by a dashboard. I have managed to perform the login and navigation process and believe that the scraping element will run smoothly after this step. I don't believe that I am targeting the right elements or am not structuring the VBA sequence correctly.

I am attempting to trigger the 'consultant view' within the HTML below:

<div style="width:100%; clear:both">
    <ul class="tab_menu clearfix" style="padding-top:5px;">
        <li id="site_ti" class="table_tab_item">
            <a href="#" onclick="update_table_tab('site'); return false;">By Site</a>
        </li>
        <li id="director_ti" class="table_tab_item">
            <a href="#" onclick="update_table_tab('director'); return false;">By Director</a>
        </li>
        <li id="team_lead_ti" class="table_tab_item">
            <a href="#" onclick="update_table_tab('team_lead'); return false;">By Team Manager</a>
        </li>
        <li id="consultant_ti" class="table_tab_item">
            <a href="#" onclick="update_table_tab('consultant'); return false;">By Consultant</a>
        </li>
    </ul>

I have thusfar used the following routines with no result:

These are the declarations at the beginning of the Public Sub:

Public Sub Huddle_Report_Scrape(ObjIE)
Dim ie As SHDocVw.InternetExplorer
Dim doc As MSHTML.HTMLDocument 'If you have a reference to the HTML Object Library
Dim objShell, obj, objInputs, objButtons As Object

Dim htmldoc As MSHTML.IHTMLDocument 'Document object

Dim tbl As MSHTML.IHTMLElementCollection
Dim eleColtr As MSHTML.IHTMLElementCollection 'Element collection for tr tags
Dim eleColtd As MSHTML.IHTMLElementCollection 'Element collection for td tags

Dim eleRow As MSHTML.IHTMLElement 'Row elements
Dim eleCol As MSHTML.IHTMLElement 'Column elements

Dim Table As MSHTML.HTMLTable
Dim row As MSHTML.HTMLTableRow
Dim cell As MSHTML.HTMLTableCell
Dim col As MSHTML.HTMLTableCol    

Below is the function I am calling to trigger the consultant view.

Function FnConsultantView(ObjPage)
With ObjPage

Set li = .getElementByValue("consultant")
    With li
        .Focus
        .FireEvent "onclick"
    End With
End With
MsgBox ("Operation Completed")

I have also attempted to use elements from the following post without much luck: FireEvent and IE11

Community
  • 1
  • 1
Strategorm
  • 21
  • 1
  • `getElementByValue` is what ? What happens when you run that code? – Tim Williams Aug 17 '16 at 19:52
  • Try ObjPage.Document.getElementByID("consultant_ti").getElementsByTagName("a")(0).Click. This should click the item. – Ryan Wildry Aug 17 '16 at 20:09
  • That has been used as well as getElementByID and it will run to the Operation Completed prompt, but will not activate the tab. – Strategorm Aug 17 '16 at 20:10
  • It worked with a FireEvent! Thank you! Function FnConsultantView(ObjPage) With ObjPage .getElementById ("consultant_ti") .getElementsByTagName("a")(0).FireEvent ("onclick") End With MsgBox ("Operation Completed") – Strategorm Aug 17 '16 at 20:15
  • You want to process the click event. The FireEvent responds to the event (Click) happening first. – Ryan Wildry Aug 17 '16 at 20:16
  • @RyanWildry seems you may post your comment as an answer. – omegastripes Aug 28 '16 at 07:53

1 Answers1

0

It worked with a FireEvent.

Function FnConsultantView(ObjPage) 
With ObjPage .getElementById ("consultant_ti") .getElementsByTagName("a")(0).FireEvent ("onclick") 
End With MsgBox ("Operation Completed")
ChrisM
  • 1,576
  • 6
  • 18
  • 29
Strategorm
  • 21
  • 1