title: Using VBA to Automate IE Login - Having Errors
body: <p><strong><em>Edited</em></strong></p>
  
  <p>So I've been tampering with my script some more, and I have copied below the current iteration of it.</p>
  
  <p>I am still getting the same error, but now it is on a new line. I also added in the source code below since the link is not accessible by everyone. I bolded the line in the code that gives the error.</p>
  
  <p>The error is:</p>
  
  <blockquote>
    <p>Method 'Document' of object 'IWebBrowser2' failed</p>
  </blockquote>
  
  <hr>
  
  <pre><code>Sub OpenCIR()
  
  Username = InputBox("Please input username")
  Password = InputBox("Please input password")
  Set objIE = CreateObject("InternetExplorer.Application")
  WebSite = "http://wsmmart.itg.ti.com/"
  With objIE
      .Visible = True
      .Navigate WebSite
  **Do While .Busy Or .readyState &lt;&gt; READYSTATE_COMPLETE**
      DoEvents
  Loop
  On Error Resume Next
  Set Element = .document.getElementsById("fld2")
  Element.Item(0).Value = Username
  
  Set Element = .document.getElementsById("fld5")
  Element.Item(0).Value = Password
  
  Do While .Busy Or .readyState &lt;&gt; READYSTATE_COMPLETE
      DoEvents
  Loop
  
  End With
  
  End Sub
  </code></pre>
  
  <hr>
  
  <p>Source Code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
     &lt;title&gt;TI-pass Login&lt;/title&gt;
  
         &lt;meta http-equiv="expires"
             content="Mon, 12 Sep 2005 02:59:54 GMT"&gt;
     &lt;meta http-equiv="pragma"
             content="no-cache"&gt;
     &lt;script language="javascript"
             src="https://ti-pass.ext.ti.com/scripts/iatc.js"
             type="text/javascript"&gt;&lt;/script&gt;
     &lt;script language="javascript"
             src="https://ti-pass.ext.ti.com/scripts/global.js"
             type="text/javascript"&gt;&lt;/script&gt;
     &lt;link rel="STYLESHEET" type="text/css" href="https://ti-       pass.ext.ti.com/styles/ticom-portal.css" /&gt;
     &lt;link rel="STYLESHEET" type="text/css" href="https://ti-pass.ext.ti.com/styles/ticom-default.css" /&gt;
     &lt;link rel="STYLESHEET" type="text/css" href="https://ti-pass.ext.ti.com/styles/genr_style.css"/&gt;
  
  &lt;/head&gt;
  
  &lt;body style="text-align: center; margin: 8px;"&gt;
  &lt;table width="100%" cellspacing="0" border="0" cellpadding="0"&gt;
     &lt;tr&gt;
        &lt;td bgcolor="#000000" width="200"&gt;&lt;img border="0" width="200"     src="https://myportal.ti.com/loginportal/images/tilogo.gif" alt="Texas Instruments" height="33"&gt;&lt;/td&gt;
        &lt;td bgcolor="#FF0000" width="100%" align="center" nowrap&gt;&lt;span class="navfontwhite" style="font-weight:bold; text-align: center;"&gt;Technology&amp;nbsp;For&amp;nbsp;Innovators&lt;sup&gt;TM&lt;/sup&gt;&lt;/span&gt;&lt;/td&gt;
     &lt;/tr&gt;
  &lt;/table&gt;
  
  
  
  
  
  
  
  
  
  
  
  &lt;!-- get edit and help --&gt;
  
  
  
  &lt;TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="100%" BGCOLOR="#999999"&gt;
  
       &lt;TR&gt;
          &lt;TD COLSPAN=2&gt;
          &lt;table
           bgcolor="white"
           width="100%"
           cellpadding=2
           cellspacing=0
           border=0&gt;
           &lt;tr&gt;&lt;td&gt;
      &lt;font color="black" face="Sans-serif"&gt;
      &lt;!-- provider content goes here --&gt;
  
  
  
  
  
  
  
  
  
  
  
  
        &lt;script language="javascript"
             src="https://myportal.ti.com/loginportal/scripts/global.js"
             type="text/javascript"&gt;
        &lt;/script&gt;
  
        &lt;link rel="STYLESHEET" type="text/css"
             href="https://myportal.ti.com/loginportal/css/genr_style.css"&gt;
  
      &lt;style type="text/css" charset="utf-8"&gt;
      .ui-state-error {background:url(https://focus.ti.com/graphics/shared/css/form-error-bg.gif) no-repeat #fff;border:1px solid #B81900;color:#B81900;padding-left:20px;}
     &lt;/style&gt;
        &lt;table cellspacing="0" cellpadding="0" width="100%"  border="0"&gt;
  
  
          &lt;tr&gt;
            &lt;td&gt;&lt;span class="pagetitle2"&gt;TI-&lt;em&gt;pass&lt;/em&gt; Login&lt;/td&gt;:&lt;/span&gt;&amp;nbsp;&lt;span class="pgsubtitle"&gt;&lt;/span&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td&gt;&lt;img src="https://myportal.ti.com/loginportal/myti_images/s.gif" width="1" height="5" alt="" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
            &lt;td class="divline"&gt;&lt;img    src="https://myportal.ti.com/loginportal/myti_images/s.gif" width="1" height="1" alt="" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
            &lt;td&gt;&lt;img src="https://myportal.ti.com/loginportal/myti_images/s.gif" width="1" height="12" alt="" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
  
  
  
          &lt;tr&gt;
            &lt;td valign="top"&gt;&lt;p&gt;Welcome to TI's secure log-in site! Enter your User ID and Password:&lt;/p&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
        &lt;/table&gt;
  
  &lt;form action="https://ti-pass.ext.ti.com/cgi-bin/login/login.pl"
              method="post" name="userid_form" enctype="application/x-www-form-    urlencoded" onsubmit="return validateLoginForm(this);"&gt;
  
        &lt;table cellspacing="0" cellpadding="0"  border="0"&gt;
          &lt;tr&gt;
            &lt;td&gt;&lt;input type="image" border="0" name="enter" width="1" height="1" src="https://myportal.ti.com/loginportal/myti_images/s.gif" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
        &lt;/table&gt;
        &lt;table cellspacing="0" cellpadding="0" width="80%"  border="0"&gt;
           &lt;tr&gt;
             &lt;td colspan="4"&gt;&lt;img   src="https://myportal.ti.com/loginportal/myti_images/s.gif" width="1" height="15" alt="" border="0" /&gt;&lt;/td&gt;
           &lt;/tr&gt;
           &lt;tr&gt;
  
            &lt;td valign="top" &gt;
  
              &lt;table cellspacing="0" cellpadding="0"   border="0"&gt;
  
              &lt;/table&gt;
  
  
              &lt;table cellspacing="0" cellpadding="0"  border="0"&gt;
  
                &lt;!-- Form Item --&gt;
                &lt;tr&gt;
                  &lt;td width="20%" &gt;&amp;nbsp;&lt;/td&gt;
                  &lt;!-- Prompt --&gt;
                  &lt;td class="bodyfontb" align="left"
                      nowrap&gt;&lt;strong&gt;User ID&lt;/strong&gt;&lt;/td&gt;
                  &lt;!-- Info --&gt;
  
                  &lt;td class="bodyfont" align="center"
                      width="15"&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;!-- Control --&gt;
                  &lt;!-- td  --&gt;
                  &lt;td class="bodyfont" style="font-size:12px;" align="left"
                      nowrap&gt;&lt;input type="text" name="fld2"  value="a0224681" size="20" maxlength="100" tabindex="101" class="frmtxtfld" id="fld2" onblur="validateEmailTIPass(this.id)" /&gt;&lt;!-- /span --&gt;&lt;/td&gt;
                  &lt;td width="50%"&gt;&amp;nbsp;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;!-- Form Item --&gt;
                &lt;tr&gt;
                  &lt;td width="20%" &gt;&amp;nbsp;&lt;/td&gt;
                  &lt;!-- Prompt --&gt;
                  &lt;td class="bodyfontb" align="left"
                      nowrap&gt;&lt;strong&gt;Password&lt;/strong&gt;&lt;/td&gt;
                  &lt;!-- Info --&gt;
                  &lt;td class="bodyfont" align="center"
                      width="15"&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;!-- Control --&gt;
                  &lt;td class="bodyfont" style="font-size:12px;" align="left"
                      nowrap&gt;&lt;input type="password" name="fld5"  size="20"  maxlength="12" tabindex="102" class="frmtxtfld" id="fld5" autocomplete="off" /&gt;&lt;!-- /span --&gt;&lt;/td&gt;
  
                  &lt;td width="50%"&gt;&amp;nbsp;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                &lt;!-- Form Item --&gt;
                  &lt;td width="20%" &gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td class="bodyfont" align="center"
                      width="15"&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td class="bodyfontb" align="left" valign="top"&gt;
                  &lt;!-- Prompt --&gt;                &lt;!-- Info --&gt;                &lt;!--     Control --&gt;
                    &lt;input type="image" tabindex="103"
                             src="https://myportal.ti.com/loginportal/myti_images/myti_gl_submit.gif"
                           width="61"
                           height="16" border="0"
                           alt="Submit"
                           name="Submit" /&gt;&lt;!-- /span --&gt;
                  &lt;/td&gt;
                  &lt;td width="50%"&gt;&amp;nbsp;&lt;/td&gt;
                &lt;/tr&gt;
                              &lt;!-- Form Item --&gt;
                &lt;tr&gt;
                  &lt;td width="20%" &gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td class="bodyfont" align="center"
                      width="15"&gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td class="bodyfont" align="left" valign="top" colspan="2"&gt;
                  &lt;!-- Prompt --&gt;                &lt;!-- Info --&gt;                &lt;!-- Control --&gt;
                     &lt;input type="checkbox" name="fld3" value="1" CHECKED  tabindex="104" /&gt;Remember me |
                        &lt;script type="text/javascript"&gt;
                          document.write('&lt;a href=\"javascript:popWin(\'https://ti-pass.ext.ti.com/login/rememberme_pu.html\',\'WhatThis\',\'width=405,height=415\')\" class=\"bodyfont\" style=\"color:#003399; font-size:10px;\"&gt;What\'s this?&lt;/a&gt;&lt;br /&gt;');
                         &lt;/script&gt;
                     &lt;noscript&gt;&lt;a href="https://ti-pass.ext.ti.com/login/rememberme_pu.html" class="bodyfont" style="color:#003399; font-size:10px;" target="_blank"&gt;What's this&lt;/a&gt;&lt;br /&gt;&lt;/noscript&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td width="20%" &gt;&amp;nbsp;&lt;/td&gt;
                  &lt;td colspan=4&gt;
                    &lt;p&gt;
                      To access this site, you must have your browser
                      set to accept temporary cookies. If you need help
                      enabling cookies, please review the following:&lt;br&gt;
                      &lt;a href="https://ti-pass.ext.ti.com/cookie_help.html"
                         target="_blank"
                         onclick="cookie_pop();return false;"&gt;How to enable cookies on your browser&lt;/a&gt;.
                    &lt;/p&gt;
                  &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                  &lt;td&gt;&amp;nbsp;&lt;br /&gt;&lt;/td&gt;
                &lt;/tr&gt;
              &lt;/table&gt;
  
            &lt;/td&gt;
  
            &lt;td width="10"&gt;&lt;img   src="https://myportal.ti.com/loginportal/myti_images/s.gif" width="10" height="1" hspace="0" vspace="0" border="0" alt="" /&gt;&lt;/td&gt;
            &lt;td class="divline" width="1"&gt;&lt;img src="https://myportal.ti.com/loginportal/myti_images/s.gif" width="1" height="1" hspace="0" vspace="0" border="0" alt="" /&gt;&lt;/td&gt;
            &lt;td valign="top"&gt;
              &lt;table cellspacing="0" cellpadding="0" width="100%"   border="0"&gt;
                &lt;tr&gt;
                  &lt;td valign="top"&gt;
  
                   &lt;div style="padding-left: 10px;"&gt;
                    Forgot your password?&lt;br /&gt;                  &lt;div style="padding-top: 5px;"&gt;
                    &lt;/div&gt;
                    &lt;a href="https://ti-pass.ext.ti.com/cgi-bin/reg/recpwd/recoverpwd1.pl?lt=genr&amp;amp;URI=http://wsmmart.itg.ti.com:80/"&gt;&lt;img
                     src="https://myportal.ti.com/loginportal/myti_images/btn_recover_password.gif"
                       width="137"
                       height="16" border="0"
                       alt="Recover Password" /&gt;&lt;/a&gt;
                    &lt;/div&gt;
  
                  &lt;/td&gt;
                &lt;/tr&gt;
              &lt;/table&gt;
            &lt;/td&gt;
  
    &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;!-- Hidden Parameters --&gt;
  
                       &lt;input type="hidden" name="xcon_legal_warn" value="1" /&gt;
  
                       &lt;input type="hidden" name="j3" value="1" /&gt;
  
                       &lt;input type="hidden" name="fld1" value="1aU4Mui39Vp" /&gt;
  
                       &lt;input type="hidden" name="portal" value="1" /&gt;
  
                       &lt;input type="hidden" name="j5" value="2" /&gt;
  
                       &lt;input type="hidden" name="OKPage"  value="http://wsmmart.itg.ti.com:80/" /&gt;
  
                       &lt;input type="hidden" name="fld4" value="all" /&gt;
  
                       &lt;input type="hidden" name="ErrPage" value="https://myportal.ti.com:443/portal/dt?j3=1&amp;j5=2&amp;OKPage=http%3A%2F%2Fwsmmart.itg.ti.com%3A80%2F" /&gt;
  
  &lt;input type="hidden" name="TI549_token"  value="da08939409d31024ffcefa31351ef4b8b28c02ec" &gt;
  &lt;script type="text/javascript" src="https://myportal.ti.com/loginportal/js/shared/myti-validations.js"&gt;&lt;/script&gt;
    &lt;!-- Set focus of cursor --&gt;
    &lt;script language="javascript"&gt;
  
      document.userid_form.fld5.focus();
  
  &lt;/script&gt;
  
  &lt;/form&gt;
        &lt;hr&gt;
  
  
        &lt;table cellspacing="0" cellpadding="0" width="100%"   border="0"&gt;
          &lt;tr&gt;
  
            &lt;td width="20%" &gt;&lt;img  src="https://myportal.ti.com/loginportal/myti_images/s.gif" width="1" height="15" alt="" border="0" /&gt;&lt;/td&gt;
  
            &lt;td&gt;
              &lt;p class="disclaim"&gt;&lt;b&gt;NOTICE&lt;/b&gt;&lt;/p&gt;
              &lt;p class="disclaim"&gt;
                This is a proprietary system of Texas Instruments Incorporated (TI) or its licensors.
                This system is for the use of authorized users only. Individuals using this system are
                subject to having all of their activities on this system monitored and recorded in order
                to verify that they have appropriate authority and do not use this  system for any
                inappropriate or unlawful purpose. Anyone using this system expressly consents to such
                monitoring. If monitoring reveals unauthorized, inappropriate or possible unlawful activity,
                system personnel will provide information derived from such monitoring to TI management or
                outside legal authorities, as appropriate. Misuse of this system may result in revocation
                or limitation of an individual's access to this system in addition to any other appropriate
                remedies.  Misuse of this system by TI employees may result in disciplinary action,
                including termination.
              &lt;/p&gt;&lt;tr&gt;
            &lt;/td&gt;
          &lt;/tr&gt;
        &lt;/table&gt;
        &lt;hr&gt;
  
  
      &lt;/font&gt;
           &lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
          &lt;/TD&gt;
        &lt;/TR&gt;
      &lt;/TABLE&gt;
  
      &lt;img src="/portal/desktop/images/nothing.gif" height="8" width="0" border="0" alt=""&gt;&lt;br&gt; 
  
  
  
  
  
  &lt;!--  
  
  
  
  
  
  
  
  
  
  
  
      &lt;TABLE BORDER="0" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"&gt;
        &lt;TR BGCOLOR="#333366"&gt;
      &lt;TD VALIGN="MIDDLE" NOWRAP&gt;
        &lt;FONT
          COLOR="#FFFFFF"
          FACE="SANS-SERIF"&gt;
          &amp;nbsp;&lt;B&gt;Sun JavaTM System Portal Server 6 2004Q2&lt;/B&gt;
        &lt;/FONT&gt;
      &lt;/TD&gt;
      &lt;TD ALIGN="RIGHT" VALIGN="MIDDLE"  NOWRAP&gt;
        &lt;P ALIGN="RIGHT"&gt;
          &lt;FONT COLOR="#FFCC00" FACE="SANS-SERIF" SIZE="+0"&gt;
            &lt;A HREF="https://myportal.ti.com/portal/dt" class="noUnderline"&gt;
          &lt;FONT COLOR="#FFFFFF" CLASS="nonuw"&gt;Home&lt;/FONT&gt;&lt;/A&gt; |
            &lt;A HREF="https://myportal.ti.com/portal/dt? action=edit&amp;provider=WirelessJSPClientConfigContainer" class="noUnderline"&gt;
      &lt;FONT COLOR="#FFFFFF" CLASS="nonuw"&gt;Mobile Devices&lt;/FONT&gt;&lt;/A&gt; |
            &lt;A HREF="https://myportal.ti.com/portal/docs/en/desktop/usedesk.htm" onClick="javascript: var helpWin=window.open ('https://myportal.ti.com/portal/docs/en/desktop/usedesk.htm', 'wthelp', 'width=600,height=400,hotkeys=no,status=no,resizable=yes,scrollbars=yes,toolbar=yes'); helpWin.focus();return false;" class="noUnderline"&gt;
          &lt;FONT COLOR="#FFFFFF" CLASS="nonuw"&gt;Help&lt;/FONT&gt;&lt;/A&gt; |
            &lt;A HREF="https://myportal.ti.com/portal/dt?action=logout" onClick="closeWindows(); return true;" class="noUnderline"&gt;
          &lt;FONT COLOR="#FFFFFF" CLASS="nonuw"&gt;
            &lt;B&gt;Log Out&lt;/B&gt;
          &lt;/FONT&gt;&lt;/A&gt;&amp;nbsp;
          &lt;/FONT&gt;
        &lt;/P&gt;
      &lt;/TD&gt;
        &lt;/TR&gt;
      &lt;/table&gt;
  
   --&gt;
  
  
  
  
  &lt;table cellpadding="0" cellspacing="10" border="0" width="100%"&gt;
     &lt;tr&gt;
      &lt;td width="Right_Side_Width" align="center"&gt;
        &lt;table&gt;
  
          &lt;tr&gt;
            &lt;td width="50%"&gt;&lt;/td&gt;
            &lt;td align="right"&gt;&lt;img height="14" alt="Texas Instruments"
                src="https://myportal.ti.com/loginportal/myti_images/footerlogo.gif" width="117"
                border="0"&gt;&lt;/td&gt;
            &lt;td class="footerfontcopy" nowrap="nowrap"&gt;&amp;nbsp; &amp;copy; &lt;a
                class="footerfontcopy"
                href="http://www.ti.com/corp/docs/copyright.htm"&gt;Copyright
                1995-2013&lt;/a&gt; Texas Instruments Incorporated. All rights
                reserved.&lt;/td&gt;
            &lt;td width="50%"&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
        &lt;/table&gt;
        &lt;span class="footerfonttrade" valign="top" align="center"&gt;&lt;a
        class="footerfonttrade"
        href="http://www.ti.com/corp/docs/trademrk.htm"&gt;Trademarks&lt;/a&gt; | &lt;a
        class="footerfonttrade"
        href="http://www.ti.com/pub/docs/privacy.htm"&gt;Privacy Policy&lt;/a&gt; |
        &lt;a class="footerfonttrade"
        href="http://www.ti.com/sc/docs/disclaim.htm"&gt;Terms of Use&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;
     &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/HTML&gt;
  </code></pre>