我正在撰寫一個宏,它將加載一個網頁,登錄它并從表中獲取資料。感謝這里的幾個主題,我已經做到了:
Sub sail2()
Dim ie As Object
Set ie = New(InternetExplorer.Application")
ie.Visible = True
ie.Navigate "http://pfrwtekref/websail/"
With ie
Dim oLogin As Object, oPassword As Object
Set oLogin = .document.getElementById("txtPwd")(0)
Set oPassword = .document.getElementById("txtPwd")(0)
oLogin.Value = test
oPassword.Value = test
.document.forms(0).submit
End With
End Sub
但是如果我啟動宏和“錯誤 462 - 服務器不可用”,我有兩種型別的錯誤“自動化錯誤”
誰能幫我 ?感謝閱讀,祝您有美好的一天!
uj5u.com熱心網友回復:
第一個問題似乎是您在第三行的逗號不匹配;但是,看到您在抱怨自動化錯誤,我認為這可能只是本網站上的一個錯字。
我看不到您的內部網站,所以我只是猜測,但我懷疑下一個問題是沒有 ID 為“txtPwd”的元素。您可以通過按 Ctrl-Shift-C 然后選擇用戶名和密碼輸入框來檢查以確認。
最后,根據站點的設定方式,您的 .document.forms(0).submit 可能無法正常作業。您可能需要找到提交按鈕類提交的 ID。下面是我為此類任務創建的一個函式:
Function logIn(userName As String, password As String) As Boolean
'This routine logs into the grade book using given credentials
Dim ie As New InternetExplorer
Dim doc As HTMLDocument
On Error GoTo loginFail
ie.Navigate "[website here]"
'ie.Visible = True
Do While ie.ReadyState <> READYSTATE_COMPLETE Or ie.Busy: DoEvents: Loop 'Wait server to respond
Set doc = ie.Document
doc.getElementsByName("u_name").Item(0).Value = userName 'These may be different for you
doc.getElementsByName("u_pass").Item(0).Value = password
doc.getElementsByClassName("btn").Item(0).Click
Do While ie.ReadyState <> READYSTATE_COMPLETE Or ie.Busy: DoEvents: Loop 'Wait server to respond
Set doc = ie.Document
'Add a check to confirm you aren't on the same page
ie.Quit
Set ie = Nothing
LogIn = True
Exit Function
loginFail:
MsgBox "There was an issue logging in. Please try again."
logIntoGradeBook = False
End Function
請注意,我正在處理的站點設定不佳,因此我需要切換到 GetElementsByName 和 GetElementsByClassName 才能訪問我需要的內容。你可能對 ID 沒問題。
uj5u.com熱心網友回復:
您為什么不嘗試使用Excel PowerQuery從您需要的表中獲取資料?完成所需的列后,您只需單擊關閉并加載,選擇資料模型 e 現在您可以在加載檔案時使用宏來執行資料透視表,或者只使用資料透視表,當您使用重繪 時資料將被重繪 資料功能區中的資料。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/419318.html
標籤:
