[英]How to use getElementByID in VBA?
因此,我進行了此測試,該測試首先使用inputbox詢問Facebook的電子郵件和密碼。 然后,它應該轉到Internet Explorer上的(www.facebook.com),並使用您的電子郵件和密碼登錄,但是它給了我錯誤消息(需要運行時錯誤'424'對象)。 我不知道這段代碼有什么問題,所以如果您能幫助我會很高興。
Sub FB_Login()
Dim Site As Object
Set Site = CreateObject("InternetExplorer.application")
Dim FB_ID As String
Dim FB_PW As String
Dim URL As String
FB_ID = InputBox("Give me email for FB")
FB_PW = InputBox("Give me password for FB")
URL = "Facebook.com"
Site.navigate URL
While Site.busy
Wend
Site.document.getElementById("email").Value = FB_ID 'Gives error
Site.document.getElementById("pass").Value = FB_PW 'Run-time error '424'
Site.document.getElementById("loginbutton").Click 'Object required
While Site.busy
Wend
Site.Visible = True
End Sub
謝謝大家的提前回答。
也許這會有所幫助嗎?
Option Explicit
Sub FB_Login()
Dim Site As Object
Set Site = CreateObject("InternetExplorer.application")
Dim FB_ID As String
Dim FB_PW As String
Dim URL As String
FB_ID = InputBox("Give me email for FB")
FB_PW = InputBox("Give me password for FB")
URL = "Facebook.com"
Site.navigate URL
While Site.busy
Wend
Dim oHTMLDoc As Object
Set oHTMLDoc = Site.document
oHTMLDoc.getElementById("email").Value = FB_ID 'Gives error
oHTMLDoc.getElementById("pass").Value = FB_PW 'Run-time error '424'
oHTMLDoc.getElementById("loginbutton").Click 'Object required
While Site.busy
Wend
Site.Visible = True
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.