2017-02-15 41 views
2

私は実行時エラー「91」:VBAでのURLのデータのスクリプトが

実行時エラー「91」を取得していながら、オブジェクト変数またはでブロック変数が設定されていません:オブジェクト変数またはWithブロック変数が

を設定していません

しばらくURLデータスクリプティング

私は私のコードすなわちpopup.clickを実行することになって自分のコードの最後に、このエラーを取得していますが。私はF8の助けを借りて、ステップによって、コードのステップの下にこれを実行する場合、私は、このようなエラーに直面していませんでしたが、私は実行]ボタンの助けを借りて、コードを実行する場合、私は、このエラーに直面しています気づい

一つ。

1つ以上のこと私はちょうど私がとコードを実行すると言及したいと思います実行ボタン私はチェックとして何も表示されません。

 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

は、2本のラインとの間に十分な時間が正常に実行したときに、ちょうどR3uK卿@ popup.Click' – R3uK

+0

''前DoEvents'を追加しようがないことかもしれないが、私はsame.Iを追加しようとしていますコード** Do While While appIE.BusyまたはappIE.readyState <> 4:DoEvents:Loop **コードですが、エラーは修正されません。 – sagar

+0

うん、私はあなたがそこでそれを使用しているのを見ましたが(そこには、ページが読み込まれるのを待つのに使われます)、私はあなたが 'Set popup = ap ...'と 'popup 'の間に追加することをお勧めします。クリックしてください。** – R3uK

答えて

0

これを試してみて、あなたがメッセージボックスを持っている場合、またはそれが動作するかどうか私に教えて:

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 
関連する問題