title: Select Link on website after login with Excel 2013 VBA
body: <p>I am trying to open a link on a webpage after logging in with VBA in excel. So far my code successfully opens the website and logs on. However, no examples I've seen in the forums seem to work for actually opening the next link.</p>
  
  <p>HTML Code from the site:</p>
  
  <pre><code>&lt;td class="nrmlFnt nWrap"&gt;
      &lt;a id="ctl00_wpm_ac_ac_rbk_ctl01_lnkBrokerageAccountName" oncontextmenu="return false;" href="javascript:__doPostBack('ctl00$wpm$ac$ac$rbk$ctl01$lnkBrokerageAccountName','')"&gt;Retirement&lt;/a&gt;    
      &lt;/td&gt;
  </code></pre>
  
  <p>While the innertext and ID are unique, I've been unable to select them.</p>
  
  <p>I am new to VBA and may not have been implementing some of the solutions to similar problems quite right. Below is my code:</p>
  
  <pre><code>Dim HTMLdoc As HTMLDocument
  Dim MyBrowser As InternetExplorer
  
  Private Sub btnUpdate_click()
  
   'Create Variables for web browsing
   Dim MyHTML_Element As IHTMLElement 'Elements to search for: textboxes, buttons etc...
   Dim MyURL As String
  
   'Dim IE As InternetExplorerMedium
  
   'Clear errors to prevent from stopping code
   On Error GoTo Err_Clear
   'Input Desired webpage login URL
   MyURL = "https://client.schwab.com/Login/SignOn/CustomerCenterLogin.aspx"
  
   Set MyBrowser = New InternetExplorer 'Creates new browser session
   MyBrowser.Silent = True 'Avoids Pop-ups
   MyBrowser.navigate MyURL 'Navigates to URL
   MyBrowser.Visible = True 'Opens browser window. Change to False to run w/o opening
  
   'Wait for web page to fully load
   Do
      DoEvents
   Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
  
   Set HTMLdoc = MyBrowser.document
   'Enter Username:
   HTMLdoc.all.ctl00_WebPartManager1_CenterLogin_LoginUserControlId_txtLoginID.Value = "username"
   'Enter Password:
   HTMLdoc.all.txtpassword.Value = "password"
  
   'Click Login button on webpage:
  For Each MyHTML_Element In HTMLdoc.getElementsByTagName("a")
   If MyHTML_Element.ID = "ctl00_WebPartManager1_CenterLogin_LoginUserControlId_btnLogin" Then MyHTML_Element.Click: Exit For
   Next
  
   'Wait for web page to fully load
  Do
      DoEvents
   Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
  
   'Select Account to be displayed:
  Set HTMLdoc = MyBrowser.document
  Set e = HTMLdoc.getElementById("ctl00_wpm_ac_ac_rbk_ctl01_lnkBrokerageAccountName")
  e.Click
  
  
   'Wait for web page to fully load
   Do
      DoEvents
   Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
  
  'Define Err_Clear Function:
  Err_Clear:
   If Err &lt;&gt; 0 Then
   Err.Clear
   Resume Next
   End If
  
  End Sub
  </code></pre>
  
  <p>I feel this should be something pretty simple like the following, but it hasn't worked:</p>
  
  <pre><code>Set MyHTML_Element= MyBrowser.Document.getElementByID("ctl00_wpm_ac_ac_rbk_ctl01_lnkBrokerageAccountName").getElementsByTagName("a")(0)
    MyHTML_Element.Click 
  </code></pre>
  
  <p>I have also tried the following with no success:</p>
  
  <pre><code>For Each MyHTML_Element In HTMLdoc.getElementsByTagName("a")
   If MyHTML_Element.ID = "ctl00_wpm_ac_ac_rbk_ctl01_lnkBrokerageAccountName" Then MyHTML_Element.Click: Exit For
   Next
  </code></pre>
  
  <p>The webpage loads, logs in and then... nothing happens.</p>