2016-08-31 10 views
0

ウェブサイトにログインしてから、同じウェブサイト内で情報をクリックして入力し続けようとしています。しかし、コードを実行すると、オブジェクトが忘れられているというエラーが表示されます。ここでInternet Explorerで作成したオブジェクトへの参照を維持する

ここでコード

Sub Vba2HtmlForm() 
    Dim IE as Object 
    Dim frm as variant 
    dim element as variant 

    Set IE = CreateObject("InternetExplorer.Application") 
    IE.Visible = True 
    IE.navigate "https://www.programworkshop.com/6.0.0.0/login/login.aspx?skin=default&lang=enu" 
    While IE.readyState <> 4: DoEvents: Wend 

    ''trying to get form by ID'' 

    IE.document.getElementById("Login").Value = "[email protected]" 

    IE.document.getElementById("Pass").Value = "somepassword" 
    IE.document.getElementById("btnlogin").Click 
    While IE.readyState <> 4: DoEvents: Wend 

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

    ' And then here is where I run into the following error: 
    ' Run-time error '424': 
    ' Object Required 

    IE.document.all("sd5").Click 
    '''just a note here. I have also tried getelementbyId and getelementbyname with no luck'''' 

End Sub 

である、それはその場所を失ったとき、あなたがされて移動した後HTML

<a id="sd5" class="node" href="javascript:treeAction(strURL5)" onmouseover="window.status='Examinees';return true;" onmouseout="window.status='';return true;" onclick="javascript: d.s(5);">Examinees</a> 
+0

のようにそれを呼び出します。 2つのブロックの間に残りのコードを追加するには[編集]してください。 –

+0

これはすべてのコードです – Jexon

答えて

0

です。あなたがリダイレクトされず、IEの1つのインスタンスだけがURLを持っていると仮定して、あなたがナビゲートしたURLを渡すことによって、正しいIEオブジェクトを取得するための小さな方法を使用することができます。 Microsoft Shell Controls and Automationへの参照を追加する必要があります。

は、エラーがあなたが投稿したコードの最初のブロックに関係して発生している場所を私たちは知らない

Set IE = CreateObject("InternetExplorer.Application") 
IE.Visible = True 
IE.navigate "https://www.programworkshop.com/6.0.0.0/login/login.aspx?skin=default&lang=enu" 
While IE.readyState <> 4: DoEvents: Wend 
set IE = GetWebPage("https://www.programworkshop.com/6.0.0.0/login/login.aspx?skin=default&lang=enu") 



'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
'Desc: The Function gets the Internet Explorer window that has the current 
' URL from the sURL Parameter. The Function Timesout after 30 seconds 
'Input parameters: 
    'String sURL - The URL to look for 
'Output parameters: 
    'InternetExplorer ieWin - the Internet Explorer window holding the webpage 
'Result: returns the Internet Explorer window holding the webpage 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 
Function GetWebPage(sURL As String) As InternetExplorer 
Dim winShell As Shell 
Dim dt As Date 
Dim ieWin As InternetExplorer 

dt = DateAdd("s", 30, DateTime.Now) 

Do While dt > DateTime.Now 
    Set winShell = New Shell 
    'loop through the windows and check the internet explorer windows 
    For Each ieWin In winShell.Windows 
     If ieWin.LocationURL = sURL Then 
      ieWin.Visible = True 
      Set GetWebPage = ieWin 
      Do While ieWin.Busy 
       DoEvents 
      Loop 
      Exit Do 
     Set winShell = Nothing 
     End If 
    Next ieWin 
    Set winShell = Nothing 
    DoEvents 
Loop 
End Function 
関連する問題