4

我正在尝试使用主登录页面和第二个一次性密码(OTP)页面登录我的网站。但我得到了错误

运行时错误“-2147467259 (80004005)”:

自动化错误

未指定的错误

在这一行找到:

 If InStr(wd.document.Title, "Sales Force Automation") <> 0 Then

我在这里做错了什么?我是这门语言的新手,因为我 2 天前才开始学习它。

Dim wd As SHDocVw.InternetExplorer

Sub login()
    Dim username As Range
    Dim password As Range
    Dim otp As Range
    Dim myValue As Variant

    Set wd = CreateObject("InternetExplorer.Application")
    wd.silent = True
    wd.navigate "Http://www.XXXXXXXXXXX.com"
    wd.Visible = True

    Set username = Range("B1")
    Set password = Range("B2")

    While wd.Busy
        DoEvents
    Wend

    wd.document.all.UserId.Value = username
    wd.document.all.password.Value = password

    Application.Wait (Now + TimeValue("0:00:10"))

    wd.document.all.btnobj.Click

    myValue = InputBox("Enter OTP")
    Range("B3").Value = myValue


Err_Clear:
    If Err <> 0 Then
        Err.Clear
        Resume Next
    End If

    Call FindTicketWindow
End Sub

Sub FindTicketWindow()
    Dim otp As Range

    For Each wd In CreateObject("Shell.Application").Windows
        If wd = "Internet Explorer" Then
            If InStr(wd.document.Title, "Sales Force Automation") <> 0 Then
                Application.Wait (Now + TimeValue("0:01:00"))
                Exit For
            End If
        End If
    Next wd

    Set otp = Range("B3")

    While wd.Busy
        DoEvents
    Wend

    myVar = wd.document.Title

    wd.document.all.verficationcode.Value = otp
    Application.Wait (Now + TimeValue("0:00:10"))
    wd.document.all.btnobj.Click
End Sub
4

1 回答 1

0

我以前遇到过这样的问题,我发现 VBA 正试图在该对象按照代码预期创建或更改之前对该对象执行操作。因此,在单步执行代码时,因为它在步骤之间有足够的时间来完成计算。

于 2015-05-13T03:40:18.980 回答