title: Use Excel VBA to click on a button in Internet Explorer, when the button has no "name" associated
body: <p>I'm trying to use excel to automate the value entering in a time sheet.  The time sheet is on a web page.
  Right now I'm able to load the page, enter my username and password and then entering the time sheet by itself.  See code below. </p>
  
  <p>At this point I need to click on a  button to open sub-forms.  I can't know in advance how many sub-forms there will be to open.  I know how to click on a button when it has a "name".  But in this case there's none.    So my updated code below use a loop to open every other subform. It works the first time, but when I do it again </p>
  
  <p>Could someone point me how to determine how many of those button there is in the page and how to click on each?
  Following I'm placing the code I have until now and below it, the HTML code of the page I need to interact with.  </p>
  
  <pre><code>Private Sub time_sheet_filling()
  
      Dim I As Long
      Dim IE As Object
      Dim doc As Object
      Dim objElement As Object
      Dim objCollection As Object
  
      ' Create InternetExplorer Object
      Set IE = CreateObject("InternetExplorer.Application")
      IE.Visible = True
  
      ' Send the form data To URL As POST binary request
      IE.navigate "http://timesheet.cccc.ca/timesheet/"
  
      ' Wait while IE loading...
      Do While IE.Busy
          Application.Wait DateAdd("s", 1, Now)
      Loop
  
          'Load the logon page
      Set objCollection = IE.Document.getElementsByTagName("input")
      I = 0
      While I &lt; objCollection.Length
          If objCollection(I).Name = "txtUserName" Then
              ' Set text to enter
              objCollection(I).Value = "6666"
          End If
          If objCollection(I).Name = "txtPwd" Then
              ' Set text for password
              objCollection(I).Value = "password"
          End If
          If objCollection(I).Type = "submit" And objCollection(I).Name = "btnSubmit" Then ' submit button clicking
              Set objElement = objCollection(I)
          End If
          I = I + 1
      Wend
  
      objElement.Click    ' click button to load the form
  
      ' Wait while IE re-loading...
      Do While IE.Busy
          Application.Wait DateAdd("s", 1, Now)
      Loop
  
      ' Show IE
      IE.Visible = True  
  Dim links, link
  Dim n, j
  Set links = IE.Document.getElementById("dgTime").getElementsByTagName("a")
  n = links.Length  
  For j = 0 To n - 1 Step 2
      links(j).Click
  'I have some operations to be done will post another question for this
  IE.Document.getElementById"DetailToolbar1_lnkBtnSave").Click              'save
  IE.Document.getElementById"DetailToolbar1_lnkBtnCancel").Click            'close
  Next
  
  
  
  End Sub  
  </code></pre>
  
  <p>So extract of the html code is below.  I'm trying to click the button that is coded in the last line of the html code below</p>
  
  <pre><code>&lt;table width="984" class="Grid" id="dgTime" border="1" rules="all" cellspacing="0"&gt;
    &lt;tbody&gt;
      &lt;tr class="GridHeader"&gt;
      &lt;/tr&gt;
      &lt;tr class="GridItem"&gt;
      &lt;/tr&gt;
      &lt;tr class="GridItem"&gt;
        &lt;td class="GridButtonColumn"&gt;
          &lt;a href="javascript:__doPostBack('dgTime$_ctl2$_ctl0','')"&gt;
            &lt;img src="images/toolbar/b_edit.gif"&gt;
          &lt;/a&gt;
        &lt;/td  
  </code></pre>
  
  <p>Tx Tim for the answers.  Now I'm able to select the first subform button to open it.  </p>
  
  <pre><code>links(j).click   'j = 0 
  </code></pre>
  
  <p>I then save it, close, and come back to the main form.  But then when I try to do</p>
  
  <pre><code>links(j).click   'j = 2 this time
  </code></pre>
  
  <p>the second time I get a runtime error 70:  permission denied.  Anymore kind help will be so appreciated.
  Regards</p>