title: Automate Internet Explorer: enter a value that has no "ID"
body: <p>I'm trying to use excel VBA to automate the data entering on a intranet Webpage of my company.  I know how to interact with values of a web page the fields have "id"  like in the html code below</p>
  
  <pre><code>&lt;input name="txtUserName" tabindex="1" id="txtUserName" type="text"&gt;  
  </code></pre>
  
  <p>With that kind of html code I would use something like  </p>
  
  <pre><code>IE.Document.getElementbyId("txtUserName").Value = "UserName"  
  </code></pre>
  
  <p>The problem I'm facing is that the code associated with the field I'm trying to interact is    </p>
  
  <pre><code>        &lt;HTML&gt;&lt;HEAD&gt;&lt;META content="IE=5.0000" http-equiv="X-UA-Compatible"&gt;
  &lt;SCRIPT type=text/javascript&gt;
              function ajusterFrames() {
                  var iLargeurGauche = 217;
                  var iLargeurDroite = 850;
                  var iLargeurFenetre = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
                  var iMarge = 0;
                  var sCols = "";
                  if (iLargeurFenetre &gt; (iLargeurGauche + iLargeurDroite)) {
                      iMarge = (iLargeurFenetre - (iLargeurGauche + iLargeurDroite)) / 2;}
                  sCols = (iLargeurGauche + iMarge) + ",*";
                  document.getElementById("framesetbas").cols = sCols;
                  document.getElementById("cadres").style.display = "block";}
              window.onload = ajusterFrames;
              window.onresize = ajusterFrames;
          &lt;/SCRIPT&gt;
  </code></pre>
  
  <p></p>
  
  <p>
  
      
          
              
                  
                      
                          
                              </p>
  
  <pre><code>                            &lt;TBODY&gt;
                                  &lt;TR&gt; &lt;/TR&gt;
                                      &lt;TR&gt;
                                          &lt;TD&gt;
                                          &lt;!--RECHERCHE--&gt;
                                              DIV id=Projet&gt;
                                              &lt;!--RECHERCHE--&gt;
                                                  &lt;CENTER&gt;
                                                      &lt;FIELDSET style="WIDTH: 600px" name="recherche"&gt;
                                                      &lt;LEGEND style="FONT-SIZE: 10px; FONT-FAMILY: verdana; COLOR: #767676" name="legende_recherche"&gt;
                                                      &lt;INPUT onclick=afficherRecherche(this.value); type=radio value=simple name=TypeRecherche&gt;
                                                      &lt;/DIV&gt;&lt;!------RECHERCHE AVANCÉE-------------------------------------&gt;
                                                      &lt;DIV id=divAvancee&gt;
                                                          &lt;CENTER&gt;
                                                              &lt;TABLE cellSpacing=0 cellPadding=0 border=0&gt;
                                                                  &lt;TBODY&gt;
                                                                      &lt;TR&gt;
                                                                      &lt;TR&gt;
                                                                      &lt;TR&gt;
                                                                      &lt;TR&gt;
                                                                      &lt;TR&gt;
                                                                      &lt;TR&gt;
                                                                      &lt;TD align=right&gt;
                                                                          &lt;FONT color=#003366 size=1 face=verdana&gt;No Projet :&lt;/FONT&gt;&lt;/TD&gt;
  </code></pre>
  
  <p>So I'm trying to modify the value of the field identify by:  "txtNoProjet"   Here's the code I could come up with, I tried many versions around this and still can't get it right.<br>
  UPDATED CODE TO INCLUDE SOLUTION</p>
  
  <pre><code>Private Sub entree_budget()
  
  
  Dim i As Long
  Dim IE As Object
  Dim Doc As Object
  Dim objElement As Object
  Dim objCollection As Object
  Dim buttonCollection As Object
  Dim valeur_heure As Object
  
  num_proj = Cells(1, 3)              'this is the value that I need to input
  
  ' Create InternetExplorer Object
  Set IE = CreateObject("InternetExplorer.Application")
  
  ' You can uncoment Next line To see form results
  IE.Visible = True
  
  ' Send the form data To URL As POST binary request
  IE.Navigate "http://intranet.cima.ca/fr/application/paq/projets/index.asp?v1_lang=1"
  
  ' Wait while IE loading...
  Do While IE.Busy
      Application.Wait DateAdd("s", 1, Now)
  Loop
  </code></pre>
  
  <p>'UPDATED CODE BELOW  </p>
  
  <pre><code>    Set links = IE.Document.frames(2).Document.getElementsByTagName("input")
           n = links.Length   
      While i &lt; n
              If links(i).Name = "txtMotCle" Then        
                  links(i).Value = num_proj
              End If  
    i = i+ 1  
  Wend 
  
  End Sub 
  </code></pre>
  
  <p>Can anyone help me with this?<br>
  And also if I may I will the need to click the button "search" on the bottom of the form , but I can't recognize it's syntax so I don't know how to interact with it.  Could someone tell me how to click the button that has this html code? </p>
  
  <pre><code>&lt;A href="javascript:submitForm('avancee');"&gt;
  &lt;IMG border=0 alt="Rechercher un projet" src="../../../images/fr/rechercher.gif"&gt;&lt;/A&gt;  
  </code></pre>
  
  <p>UPDATED CODE  SOLUTION FOR THIS IS:  </p>
  
  <pre><code>Set links = IE.Document.frames(2).Document.getElementsByTagName("a")
   n = links.LengtH
  i = 0
  While i &lt; n
      If links(i).href = "javascript:submitForm('avancee');" Then           
          Set objElement = links(i)
          objElement.ClicK
      End If
      i = i + 1
  Wend
  </code></pre>
  
  <p>Thank you so much in advance for the time you'll spend answering my questions.</p>