title: How to make Excel VBA automate clicking javascript a href link in IE
body: <p>I have a macro in VBA which uses Excel to automate navigating to a web-page. </p>
  
  <p>I am able to select elements by their ID and click or insert values to automate the site. </p>
  
  <p>I am stuck however when trying to 'click' a link/button which does not seem to have any ID. It is a JavaScript link: </p>
  
  <pre><code>&lt;div&gt;
  &lt;table class="table" id="ctl00_cphMaster_Results" style="width: 100%; border-collapse: collapse;" cellspacing="0"&gt;
      &lt;tbody&gt;&lt;tr&gt;
          &lt;th style="width: 70px; white-space: nowrap;" scope="col"&gt;&lt;a href="javascript:__doPostBack('ctl00$cphMaster$Results','Sort$Indicator')"&gt;True?&lt;/a&gt;&lt;/th&gt;&lt;th class="hidden" style="width: 100px;" scope="col"&gt;&lt;a href="javascript:__doPostBack('ctl00$cphMaster$Results','Sort$Reference')"&gt;Reference&lt;/a&gt;&lt;/th&gt;&lt;th scope="col"&gt;&lt;a href="javascript:__doPostBack('ctl00$cphMaster$Results','Sort$Results')"&gt;Result Number&lt;/a&gt;&lt;/th&gt;&lt;th class="hidden" scope="col"&gt;&amp;nbsp;&lt;/th&gt;&lt;th scope="col"&gt;&lt;a href="javascript:__doPostBack('ctl00$cphMaster$Results','Sort$Type')"&gt;Type&lt;/a&gt;&lt;/th&gt;&lt;th class="hidden" scope="col"&gt;&lt;/th&gt;&lt;th class="hidden" scope="col"&gt;&amp;nbsp;&lt;/th&gt;&lt;th class="hidden" scope="col"&gt;&amp;nbsp;&lt;/th&gt;
      &lt;/tr&gt;&lt;tr&gt;
          &lt;td align="center"&gt;&lt;a href="Summary02.aspx?"&gt;&lt;img title="Accepted" id="true" style="border: currentColor; border-image: none;" alt="Accepted" src="/Common/Graphics/tick_green.gif"&gt;&lt;/a&gt;&lt;img id="Accepted" style="border: currentColor; border-image: none;" src="/Common/Graphics/tick_spacer.gif"&gt;&lt;img id="Accepted" style="border: currentColor; border-image: none;" src="/Common/Graphics/tick_spacer.gif"&gt;&lt;/td&gt;&lt;td class="hidden"&gt;MyValue&lt;/td&gt;&lt;td&gt;&lt;a href="javascript:__doPostBack('ctl00$cphMaster$Results','ResultNumber$0')"&gt;ResultNumber&lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;
  </code></pre>
  
  <p></p>
  
  <p>I have attempted to click 'ResultNumber$0' or trigger it in some way but so far have been unsuccessful. How can I automate IE to click this javascript link/button? My code so far:</p>
  
  <pre><code>Sub ClickJavaLink()
  Const URL = "https://myurl"    
  Dim ie As Object
  Set ie = CreateObject("InternetExplorer.Application")
  
  With ie
      .navigate URL
      ieBusy ie
      .Visible = True
  
      For Each Item In ie.document.all
          If Item.ID = "QuickSearchField" Then
              Item.Value = 1
          End If
          If Item.ID = "QuickSearch" Then
              Item.Value = "MyValue"
          End If
          If Item.ID = "btnSearch" Then
              Item.Click
              Exit For
          End If
      Next
      ieBusy ie
  
  'code working up to this point - below code is attempt to click the javascript link but does not work   
      For Each Item In ie.document.all
          If Item.ID = "ResultNumber$0" Then
              Item.Click
              Exit For
          End If
      Next
      ieBusy ie
  End With
  </code></pre>
  
  <p>End Sub</p>
  
  <p>Sub ieBusy(ie As Object)
      Do While ie.Busy Or ie.ReadyState &lt; 4
          DoEvents
      Loop
  End Sub</p>