2017-02-15 30 views
2

我越來越運行時錯誤「91」:而在VBA URL數據腳本

運行時錯誤「91」對象變量或帶塊變量未設置:對象變量或帶塊變量未設置

而URL數據腳本

我得到這個錯誤在那裏我應該執行我的代碼,即popup.click我的代碼的結束。

一件事我注意到,如果我跑這下面的代碼一步一步F8我沒有面臨這樣的錯誤,但如果我運行按鈕的幫助下執行的代碼,我面對這個錯誤的幫助。

還有一件事我只想提一下,當我執行代碼運行按鈕彈出窗口值沒有顯示,因爲我檢查。

 Sub GoToWebsiteTest() 
     Dim appIE As InternetExplorerMedium 
     Dim tags As Object 
     Dim tagx As Object 
     Dim repo As Object 
     Dim popup As Object 
     Dim Element As HTMLButtonElement 
     Dim MyHTML_Element As IHTMLElement 
     Dim HTMLdoc As HTMLDocument 

     i = 0 
     Set appIE = New InternetExplorerMedium 
     sURL = "https://oneview.myurl.in/" 
     With appIE 
      .navigate sURL 
      .Visible = True 
     End With 

     Do While appIE.Busy Or appIE.readyState <> 4 
      DoEvents 
     Loop 

     appIE.document.getElementById("Username").Value = "xxx" 
     appIE.document.getElementById("Password").Value = "xxxx" 

     i = InputBox("type") 

     appIE.document.getElementById("txtcaptcha").Value = i 

     Set tags = appIE.document.getElementsByTagName("input") 

     For Each tagx In tags 
     If tagx.Type = "submit" Then 
      tagx.Click 
     End If 
     Next 

     Do While appIE.Busy Or appIE.readyState <> 4 
      DoEvents 
     Loop 

     Set popup = appIE.document.getElementById("ctl00_MainContent_gridUser_ctl00_ctl04_lnkG2") 

' Here I am getting Object variable or With block variable not set error 

    popup.Click 
+0

可能是沒有正常運行時,嘗試添加'DoEvents'之前'popup.Click' – R3uK

+0

@ R3uK主席先生,我已經試過same.I添加兩線之間有足夠的時間代碼**雖然appIE.Busy或appIE.readyState <> 4:DoEvents:循環**代碼,但仍然錯誤沒有得到糾正。 – sagar

+0

是的,我看到你在那裏使用它(那裏,它用於等待頁面加載),但我建議你**將它添加到'Set popup = ap ...'和'popup之間。點擊'。** – R3uK

回答

0

試試這個,讓我知道如果你有MSGBOX或者工作:

Sub GoToWebsiteTest() 
    Dim appIE As InternetExplorerMedium 
    Dim tags As Object 
    Dim tagx As Object 
    Dim repo As Object 
    Dim popup As Object 
    Dim Element As HTMLButtonElement 
    Dim MyHTML_Element As IHTMLElement 
    Dim HTMLdoc As HTMLDocument 

    i = 0 
    Set appIE = New InternetExplorerMedium 
    sURL = "https://oneview.myurl.in/" 
    With appIE 
     .navigate sURL 
     .Visible = True 
    End With 

    Do While appIE.Busy Or appIE.readyState <> 4 
     DoEvents 
    Loop 

    appIE.document.getElementById("Username").Value = "xxx" 
    appIE.document.getElementById("Password").Value = "xxxx" 

    i = InputBox("type") 

    appIE.document.getElementById("txtcaptcha").Value = i 

    Set tags = appIE.document.getElementsByTagName("input") 

    For Each tagx In tags 
    If tagx.Type = "submit" Then 
     tagx.Click 
    End If 
    Next 

    Do While appIE.Busy Or appIE.readyState <> 4 
     DoEvents 
    Loop 



    Set popup = appIE.document.getElementById("ctl00_MainContent_gridUser_ctl00_ctl04_lnkG2") 

    DoEvents 
    If Not popup Is Nothing Then 
     popup.Click 
    Else 
     MsgBox "popup is not defined!", vbOKOnly + vbCritical 
    End If 

    '''rest of your code 
End Sub 
0

我已經注意到這個問題與進行事件所以,我必須改變一樣,並試圖此下方代碼工作正常。

Sub GoToWebsiteTest() 
Dim appIE As InternetExplorerMedium 
Dim tags As Object 
Dim tagx As Object 
Dim repo As Object 

Dim Element As HTMLButtonElement 
Dim MyHTML_Element As IHTMLElement 
Dim HTMLdoc As HTMLDocument 

i = 0 
Set appIE = New InternetExplorerMedium 
sURL = "https://oneview.myurl.in/" 
With appIE 
    .navigate sURL 
    .Visible = True 
End With 

Do While appIE.Busy Or appIE.readyState <> 4 
    DoEvents 
Loop 

appIE.document.getElementById("Username").Value = "xxx" 
appIE.document.getElementById("Password").Value = "xxxx" 

i = InputBox("type") 

appIE.document.getElementById("txtcaptcha").Value = i 

Set tags = appIE.document.getElementsByTagName("input") 

For Each tagx In tags 
If tagx.Type = "submit" Then 
    tagx.Click 
End If 
Next 

Application.Wait (Now + TimeValue("00:00:05")) 

Dim popup As Object 
Set popup = appIE.document.getElementById("ctl00_MainContent_gridUser_ctl00_ctl04_lnkG2") 

popup.Click