2013-03-26 68 views
1

嗨我已經想出了一個代碼,它將打開Internet Explorer,導航到網站,輸入用戶名和密碼,最後點擊登錄按鈕。VBA宏打開Mozilla Firefox

的代碼是:

Public Sub LOGIN() 

    Dim objIE As SHDocVw.InternetExplorer 
    Dim htmlDoc As MSHTML.HTMLDocument 
    Dim htmlInput As MSHTML.HTMLInputElement 
    Dim htmlColl As MSHTML.IHTMLElementCollection 

    Set objIE = New SHDocVw.InternetExplorer 

    With objIE 
     .Navigate "https://website.co.in" ' Main page 
     .Visible = 1 
     Do While .READYSTATE <> 4: DoEvents: Loop 
     Application.Wait (Now + TimeValue("0:00:02")) 

     Set htmlDoc = .document 
     Set htmlColl = htmlDoc.getElementsByTagName("INPUT") 
     Do While htmlDoc.READYSTATE <> "complete": DoEvents: Loop 
     For Each htmlInput In htmlColl 
      If htmlInput.Name = "UserName" Or htmlInput.Type = "text" Then 
       htmlInput.Value = "Adidas" 
      Else 
       If htmlInput.Name = "password" Then 
       htmlInput.Value = "Daddy123" 

       End If 
      End If 
     Next htmlInput 

     Set htmlDoc = .document 
     Set htmlColl = htmlDoc.getElementsByTagName("input") 
     Do While htmlDoc.READYSTATE <> "complete": DoEvents: Loop 
     For Each htmlInput In htmlColl 
      If Trim(htmlInput.Type) = "submit" Then 
       htmlInput.Click 
       Exit For 
      End If 
     Next htmlInput 
    End With 
End Sub 

至於我創造了這個腳本不支持Internet Explorer中的網站,我想在Firefox中打開一樣。我無能爲力,迄今爲止我還沒有嘗試過任何東西。請幫助我。

+0

可悲的是:(我不知道如何去做這件事 – user2165404 2013-03-26 11:02:54

+0

讓我們回到原來的問題。你說網站不支持Internet Explorer?那麼它有什麼問題?(與網站,這是。) – 2013-03-26 11:03:02

+0

此外,你確定你想要在純文本文件中存儲未加密的密碼嗎? – 2013-03-26 11:05:06

回答

3

Firefox不公開COM對象,因此無法控制IE的控制方式。儘管如此,您也可以使用其他自動化工具來實現您的目標。 SeleniumAutoIt

另一種選擇可能是嗅出認證業務(即發生,當你點擊「登錄」按鈕通信)的東西,如Fiddler,然後使用VBScript自動化與XMLHTTPRequest登錄:

Set req = CreateObject("MSXML2.XMLHTTP.6.0") 
req.open "POST", "http://www.example.org/", False 
req.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
req.send "field1=foo&field2=bar&..."