2013-03-26 69 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&..."