Usar o VBA para automatizar os erros de autenticação Ie

Edição

Então, tenho adulterado mais um pouco o meu guião, e copiei abaixo da iteração actual dele.

Ainda estou a ter o mesmo erro, mas agora está numa nova linha. Eu também adicionei no código fonte abaixo, uma vez que o link não é acessível por todos. Eu aparafusei a linha no código que dá o erro.

o erro é:

Método 'Document' do objecto 'IWebBrowser2' falhou


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 <> 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 <> READYSTATE_COMPLETE
    DoEvents
Loop

End With

End Sub

Código-Fonte:

<html>
<head>
   <title>TI-pass Login</title>

       <meta http-equiv="expires"
           content="Mon, 12 Sep 2005 02:59:54 GMT">
   <meta http-equiv="pragma"
           content="no-cache">
   <script language="javascript"
           src="https://ti-pass.ext.ti.com/scripts/iatc.js"
           type="text/javascript"></script>
   <script language="javascript"
           src="https://ti-pass.ext.ti.com/scripts/global.js"
           type="text/javascript"></script>
   <link rel="STYLESHEET" type="text/css" href="https://ti-       pass.ext.ti.com/styles/ticom-portal.css" />
   <link rel="STYLESHEET" type="text/css" href="https://ti-pass.ext.ti.com/styles/ticom-default.css" />
   <link rel="STYLESHEET" type="text/css" href="https://ti-pass.ext.ti.com/styles/genr_style.css"/>

</head>

<body style="text-align: center; margin: 8px;">
<table width="100%" cellspacing="0" border="0" cellpadding="0">
   <tr>
      <td bgcolor="#000000" width="200"><img border="0" width="200"     src="https://myportal.ti.com/loginportal/images/tilogo.gif" alt="Texas Instruments" height="33"></td>
      <td bgcolor="#FF0000" width="100%" align="center" nowrap><span class="navfontwhite" style="font-weight:bold; text-align: center;">Technology&nbsp;For&nbsp;Innovators<sup>TM</sup></span></td>
   </tr>
</table>











<!-- get edit and help -->



<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="100%" BGCOLOR="#999999">

     <TR>
        <TD COLSPAN=2>
        <table
         bgcolor="white"
         width="100%"
         cellpadding=2
         cellspacing=0
         border=0>
         <tr><td>
    <font color="black" face="Sans-serif">
    <!-- provider content goes here -->












      <script language="javascript"
           src="https://myportal.ti.com/loginportal/scripts/global.js"
           type="text/javascript">
      </script>

      <link rel="STYLESHEET" type="text/css"
           href="https://myportal.ti.com/loginportal/css/genr_style.css">

    <style type="text/css" charset="utf-8">
    .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;}
   </style>
      <table cellspacing="0" cellpadding="0" width="100%"  border="0">


        <tr>
          <td><span class="pagetitle2">TI-<em>pass</em> Login</td>:</span>&nbsp;<span class="pgsubtitle"></span></td>
        </tr>
        <tr>
          <td><img src="https://myportal.ti.com/loginportal/myti_images/s.gif" width="1" height="5" alt="" /></td>
        </tr>
        <tr>
          <td class="divline"><img    src="https://myportal.ti.com/loginportal/myti_images/s.gif" width="1" height="1" alt="" /></td>
        </tr>

        <tr>
          <td><img src="https://myportal.ti.com/loginportal/myti_images/s.gif" width="1" height="12" alt="" /></td>
        </tr>




        <tr>
          <td valign="top"><p>Welcome to TI's secure log-in site! Enter your User ID and Password:</p></td>
        </tr>

      </table>

<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);">

      <table cellspacing="0" cellpadding="0"  border="0">
        <tr>
          <td><input type="image" border="0" name="enter" width="1" height="1" src="https://myportal.ti.com/loginportal/myti_images/s.gif" /></td>
        </tr>
      </table>
      <table cellspacing="0" cellpadding="0" width="80%"  border="0">
         <tr>
           <td colspan="4"><img   src="https://myportal.ti.com/loginportal/myti_images/s.gif" width="1" height="15" alt="" border="0" /></td>
         </tr>
         <tr>

          <td valign="top" >

            <table cellspacing="0" cellpadding="0"   border="0">

            </table>


            <table cellspacing="0" cellpadding="0"  border="0">

              <!-- Form Item -->
              <tr>
                <td width="20%" >&nbsp;</td>
                <!-- Prompt -->
                <td class="bodyfontb" align="left"
                    nowrap><strong>User ID</strong></td>
                <!-- Info -->

                <td class="bodyfont" align="center"
                    width="15">&nbsp;</td>
                <!-- Control -->
                <!-- td  -->
                <td class="bodyfont" style="font-size:12px;" align="left"
                    nowrap><input type="text" name="fld2"  value="a0224681" size="20" maxlength="100" tabindex="101" class="frmtxtfld" id="fld2" onblur="validateEmailTIPass(this.id)" /><!-- /span --></td>
                <td width="50%">&nbsp;</td>
              </tr>
              <!-- Form Item -->
              <tr>
                <td width="20%" >&nbsp;</td>
                <!-- Prompt -->
                <td class="bodyfontb" align="left"
                    nowrap><strong>Password</strong></td>
                <!-- Info -->
                <td class="bodyfont" align="center"
                    width="15">&nbsp;</td>
                <!-- Control -->
                <td class="bodyfont" style="font-size:12px;" align="left"
                    nowrap><input type="password" name="fld5"  size="20"  maxlength="12" tabindex="102" class="frmtxtfld" id="fld5" autocomplete="off" /><!-- /span --></td>

                <td width="50%">&nbsp;</td>
              </tr>
              <tr>
              <!-- Form Item -->
                <td width="20%" >&nbsp;</td>
                <td>&nbsp;</td>
                <td class="bodyfont" align="center"
                    width="15">&nbsp;</td>
                <td class="bodyfontb" align="left" valign="top">
                <!-- Prompt -->                <!-- Info -->                <!--     Control -->
                  <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" /><!-- /span -->
                </td>
                <td width="50%">&nbsp;</td>
              </tr>
                            <!-- Form Item -->
              <tr>
                <td width="20%" >&nbsp;</td>
                <td>&nbsp;</td>
                <td class="bodyfont" align="center"
                    width="15">&nbsp;</td>
                <td class="bodyfont" align="left" valign="top" colspan="2">
                <!-- Prompt -->                <!-- Info -->                <!-- Control -->
                   <input type="checkbox" name="fld3" value="1" CHECKED  tabindex="104" />Remember me |
                      <script type="text/javascript">
                        document.write('<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;\">What\'s this?</a><br />');
                       </script>
                   <noscript><a href="https://ti-pass.ext.ti.com/login/rememberme_pu.html" class="bodyfont" style="color:#003399; font-size:10px;" target="_blank">What's this</a><br /></noscript>
                </td>
              </tr>
              <tr>
                <td width="20%" >&nbsp;</td>
                <td colspan=4>
                  <p>
                    To access this site, you must have your browser
                    set to accept temporary cookies. If you need help
                    enabling cookies, please review the following:<br>
                    <a href="https://ti-pass.ext.ti.com/cookie_help.html"
                       target="_blank"
                       onclick="cookie_pop();return false;">How to enable cookies on your browser</a>.
                  </p>
                </td>
              </tr>
              <tr>
                <td>&nbsp;<br /></td>
              </tr>
            </table>

          </td>

          <td width="10"><img   src="https://myportal.ti.com/loginportal/myti_images/s.gif" width="10" height="1" hspace="0" vspace="0" border="0" alt="" /></td>
          <td class="divline" width="1"><img src="https://myportal.ti.com/loginportal/myti_images/s.gif" width="1" height="1" hspace="0" vspace="0" border="0" alt="" /></td>
          <td valign="top">
            <table cellspacing="0" cellpadding="0" width="100%"   border="0">
              <tr>
                <td valign="top">

                 <div style="padding-left: 10px;">
                  Forgot your password?<br />                  <div style="padding-top: 5px;">
                  </div>
                  <a href="https://ti-pass.ext.ti.com/cgi-bin/reg/recpwd/recoverpwd1.pl?lt=genr&amp;URI=http://wsmmart.itg.ti.com:80/"><img
                   src="https://myportal.ti.com/loginportal/myti_images/btn_recover_password.gif"
                     width="137"
                     height="16" border="0"
                     alt="Recover Password" /></a>
                  </div>

                </td>
              </tr>
            </table>
          </td>

  </tr>
</table>

<!-- Hidden Parameters -->

                     <input type="hidden" name="xcon_legal_warn" value="1" />

                     <input type="hidden" name="j3" value="1" />

                     <input type="hidden" name="fld1" value="1aU4Mui39Vp" />

                     <input type="hidden" name="portal" value="1" />

                     <input type="hidden" name="j5" value="2" />

                     <input type="hidden" name="OKPage"  value="http://wsmmart.itg.ti.com:80/" />

                     <input type="hidden" name="fld4" value="all" />

                     <input type="hidden" name="ErrPage" value="https://myportal.ti.com:443/portal/dt?j3=1&j5=2&OKPage=http%3A%2F%2Fwsmmart.itg.ti.com%3A80%2F" />

<input type="hidden" name="TI549_token"  value="da08939409d31024ffcefa31351ef4b8b28c02ec" >
<script type="text/javascript" src="https://myportal.ti.com/loginportal/js/shared/myti-validations.js"></script>
  <!-- Set focus of cursor -->
  <script language="javascript">

    document.userid_form.fld5.focus();

</script>

</form>
      <hr>


      <table cellspacing="0" cellpadding="0" width="100%"   border="0">
        <tr>

          <td width="20%" ><img  src="https://myportal.ti.com/loginportal/myti_images/s.gif" width="1" height="15" alt="" border="0" /></td>

          <td>
            <p class="disclaim"><b>NOTICE</b></p>
            <p class="disclaim">
              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.
            </p><tr>
          </td>
        </tr>
      </table>
      <hr>


    </font>
         </td></tr></table>
        </TD>
      </TR>
    </TABLE>

    <img src="/portal/desktop/images/nothing.gif" height="8" width="0" border="0" alt=""><br> 





<!--  











    <TABLE BORDER="0" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
      <TR BGCOLOR="#333366">
    <TD VALIGN="MIDDLE" NOWRAP>
      <FONT
        COLOR="#FFFFFF"
        FACE="SANS-SERIF">
        &nbsp;<B>Sun JavaTM System Portal Server 6 2004Q2</B>
      </FONT>
    </TD>
    <TD ALIGN="RIGHT" VALIGN="MIDDLE"  NOWRAP>
      <P ALIGN="RIGHT">
        <FONT COLOR="#FFCC00" FACE="SANS-SERIF" SIZE="+0">
          <A HREF="https://myportal.ti.com/portal/dt" class="noUnderline">
        <FONT COLOR="#FFFFFF" CLASS="nonuw">Home</FONT></A> |
          <A HREF="https://myportal.ti.com/portal/dt? action=edit&provider=WirelessJSPClientConfigContainer" class="noUnderline">
    <FONT COLOR="#FFFFFF" CLASS="nonuw">Mobile Devices</FONT></A> |
          <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">
        <FONT COLOR="#FFFFFF" CLASS="nonuw">Help</FONT></A> |
          <A HREF="https://myportal.ti.com/portal/dt?action=logout" onClick="closeWindows(); return true;" class="noUnderline">
        <FONT COLOR="#FFFFFF" CLASS="nonuw">
          <B>Log Out</B>
        </FONT></A>&nbsp;
        </FONT>
      </P>
    </TD>
      </TR>
    </table>

 -->




<table cellpadding="0" cellspacing="10" border="0" width="100%">
   <tr>
    <td width="Right_Side_Width" align="center">
      <table>

        <tr>
          <td width="50%"></td>
          <td align="right"><img height="14" alt="Texas Instruments"
              src="https://myportal.ti.com/loginportal/myti_images/footerlogo.gif" width="117"
              border="0"></td>
          <td class="footerfontcopy" nowrap="nowrap">&nbsp; &copy; <a
              class="footerfontcopy"
              href="http://www.ti.com/corp/docs/copyright.htm">Copyright
              1995-2013</a> Texas Instruments Incorporated. All rights
              reserved.</td>
          <td width="50%"></td>
        </tr>

      </table>
      <span class="footerfonttrade" valign="top" align="center"><a
      class="footerfonttrade"
      href="http://www.ti.com/corp/docs/trademrk.htm">Trademarks</a> | <a
      class="footerfonttrade"
      href="http://www.ti.com/pub/docs/privacy.htm">Privacy Policy</a> |
      <a class="footerfonttrade"
      href="http://www.ti.com/sc/docs/disclaim.htm">Terms of Use</a></span></td>
   </tr>
</table>
</HTML>
Author: freginold, 2014-01-21

1 answers

Por favor veja abaixo o código de auto-autenticação que uso todos os dias: -

Sub Login()
    uname = Range("I18").Value
    pword = Range("I19").Value
    Set objIE = CreateObject("InternetExplorer.Application")
    WebSite = "http://MYDOMAIN.COM/Login.aspx"
    With objIE
      .Visible = True
      .navigate WebSite
    Do While .Busy Or .readyState <> 4
        DoEvents
    Loop
    On Error Resume Next 'This is here in case fields cant be found.
    Set Element = .Document.getElementsByName("username_input")
    Element.Item(0).Value = uname

    Set Element = .Document.getElementsByName("password_input")
    Element.Item(0).Value = pword

    Set Element = .Document.getElementsByName("login_button")(0)
    Element.Click

    Do While .Busy Or .readyState <> 4
        DoEvents
    Loop

    .navigate "http://MYDOMAIN.COM/AdminPanel.aspx"
    End With

End Sub
 0
Author: , 2014-01-21 10:21:27