2017-10-17 14 views
0

VBAを初めて使用しました。誰かが助けてくれますか?私が実行すると、オブジェクトが必要になります。私はOption Explicitを使用していません。ありがとうございました。オブジェクトが必要ですvbaのエラー - 変数を定義します

次のようなエラーが表示されます。

ie.document.getElementById("dp-status-dropdown_1").Click 

ほとんどのコードを掲載しています。助けてください。

Sub DataUpdate() 
Application.ScreenUpdating = False 
Application.DisplayAlerts = False 
Application.EnableEvents = False 
Application.DisplayAlerts = False 

Dim ie As New SHDocVw.InternetExplorer 
Dim htmldoc As MSHTML.HTMLDocument 
Dim htmlinouts As MSHTML.IHTMLElementCollection 
Dim out As MSHTML.IHTMLElement 
Dim urr As Range 
Dim Count As Long 
Dim i As Long 

Set ie = New InternetExplorer 
'  htmldoc = ie.document 

Count = ActiveSheet.Cells(Rows.Count, "H").End(xlUp).Row 

For i = 4 To Count 

    'For Each urr In Application.ThisWorkbook.Sheets("Dump").Range("H5:H" & Application.WorksheetFunction.CountA(ThisWorkbook.Sheets("Dump").Range("H:H"))).Cells 
    Set urr = Worksheets("Dump").Cells(i, 8) 
    ie.Visible = True 
    ie.navigate urr       'H4 holds the URL 
    Do 
     DoEvents 
    Loop Until ie.readyState = READYSTATE_COMPLETE 

    ThisWorkbook.Sheets("Dump").Activate 
    Dim cellvalue As Range 
    Set cellvalue = ThisWorkbook.Sheets("Dump").Range("J4") 
    If cellvalue = "" Then 
     cellvalue = "" 
    ElseIf cellvalue = "Pitch in Progress " Then 
     ie.document.getElementById("a-autoid-0-announce").Click 
     ie.document.getElementById("dp-status-dropdown_0").Click 
     Dim xx1 As Object 
     For Each xx1 In ie.document.getElementsByClassName("a-button-text") 
      If xx1.innerText Like "*OK*" Then 
       ' Debug.Print xx1.innerText 
       xx1.Click 
       Exit For 
      End If 
     Next xx1 
    ElseIf cellvalue = "Not Reachable" Then 
     ie.document.getElementById("a-autoid-0-announce").Click 
     ie.document.getElementById("dp-status-dropdown_1").Click 
     Dim xx2 As Object 
     For Each xx2 In ie.document.getElementsByClassName("a-button-text") 
      If xx2.innerText Like "*OK*" Then 
       ' Debug.Print xx1.innerText 
       xx2.Click 
       Exit For 
      End If 
     Next xx2 
    ElseIf cellvalue = "Not Interested" Then 
     ie.document.getElementById("a-autoid-0-announce").Click 
     ie.document.getElementById("dp-status-dropdown_2").Click 
     Dim xx3 As Object 
     For Each xx3 In ie.document.getElementsByClassName("a-button-text") 
      If xx3.innerText Like "*OK*" Then 
       ' Debug.Print xx1.innerText 
       xx3.Click 
       Exit For 
      End If 
     Next xx3 
    ElseIf cellvalue = "Work Started" Then 
     ie.document.getElementById("a-autoid-0-announce").Click 
     ie.document.getElementById("dp-status-dropdown_3").Click 
     Dim xx4 As Object 
     For Each xx4 In ie.document.getElementsByClassName("a-button-text") 
      If xx4.innerText Like "*OK*" Then 
       ' Debug.Print xx1.innerText 
       xx4.Click 
       Exit For 
      End If 
     Next xx4 
    ElseIf cellvalue = "Work Completed" Then 
     ie.document.getElementById("a-autoid-0-announce").Click 
     ie.document.getElementById("dp-status-dropdown_4").Click 
     Dim xx5 As Object 
     For Each xx5 In ie.document.getElementsByClassName("a-button-text") 
      If xx5.innerText Like "*OK*" Then 
       ' Debug.Print xx1.innerText 
       xx5.Click 
       Exit For 
      End If 
     Next xx5 
    ElseIf cellvalue = "Products picked up" Then 
     ie.document.getElementById("a-autoid-0-announce").Click 
     ie.document.getElementById("dp-status-dropdown_4").Click 
     Dim xx6 As Object 
     For Each xx6 In ie.document.getElementsByClassName("a-button-text") 
      If xx6.innerText Like "*OK*" Then 
       ' Debug.Print xx1.innerText 
       xx6.Click 
       Exit For 
      End If 
     Next xx6 
    ElseIf cellvalue = "Products in transit" Then 
     ie.document.getElementById("a-autoid-0-announce").Click 
     ie.document.getElementById("dp-status-dropdown_5").Click 
     Dim xx7 As Object 
     For Each xx7 In ie.document.getElementsByClassName("a-button-text") 
      If xx7.innerText Like "*OK*" Then 
       ' Debug.Print xx1.innerText 
       xx7.Click 
       Exit For 
      End If 
     Next xx7 
    ElseIf cellvalue = "Products delivered" Then 
     ie.document.getElementById("a-autoid-0-announce").Click 
     ie.document.getElementById("dp-status-dropdown_6").Click 
     Dim xx8 As Object 
     For Each xx8 In ie.document.getElementsByClassName("a-button-text") 
      If xx8.innerText Like "*OK*" Then 
       ' Debug.Print xx1.innerText 
       xx8.Click 
       Exit For 
      End If 
     Next xx8 
    ElseIf cellvalue = "MoU Signed" Then  
     ie.document.getElementById("a-autoid-0-announce").Click 
     ie.document.getElementById("dp-status-dropdown_3").Click 
     Dim xx9 As Object 
     For Each xx9 In ie.document.getElementsByClassName("a-button-text") 
      If xx9.innerText Like "*OK*" Then 
       ' Debug.Print xx1.innerText 
       xx9.Click 
       Exit For 
      End If 
     Next xx9 
    ElseIf cellvalue = "Subscription ended" Then 
     ie.document.getElementById("a-autoid-0-announce").Click 
     ie.document.getElementById("dp-status-dropdown_4").Click 
     Dim xx10 As Object 
     For Each xx10 In ie.document.getElementsByClassName("a-button-text") 
      If xx10.innerText Like "*OK*" Then 
       ' Debug.Print xx1.innerText 
       xx10.Click 
       Exit For 
      End If 
     Next xx10 

    End If 
    Dim FollowupDate As Range   
    Set FollowupDate = ThisWorkbook.Sheets("Dump").Range("K4") 
    If FollowupDate = "" Then 
     FollowupDate = "" 
    Else 
     ie.document.getElementById("pc-followUpDate-edit").Click 
     ie.document.getElementById("pc-followUpDate-input").Value = FollowupDate 
     ie.document.getElementById("pc-followUpDate-button").Click 
    End If 

    Dim pprsrc As Range   
    Set pprsrc = ThisWorkbook.Sheets("Dump").Range("L4") 
    If pprsrc = "" Then 
     pprsrc = "" 
    ElseIf pprsrc = "Call back scheduled" Then 
     ie.document.getElementById("pc-pitchInProgressRequestStatusReasonCode-edit").Click 
     ie.document.getElementById("pc-pitchInProgressRequestStatusReasonCode-input_1").Click 
     ie.document.getElementById("pc-pitchInProgressRequestStatusReasonCode-button").Click 
    ElseIf pprsrc = "Price negotiation" Then 
     ie.document.getElementById("pc-pitchInProgressRequestStatusReasonCode-edit").Click 
     ie.document.getElementById("a-autoid-30-announce").Click 
     ie.document.getElementById("pc-pitchInProgressRequestStatusReasonCode-input_2").Click 
     ie.document.getElementById("pc-pitchInProgressRequestStatusReasonCode-button").Click 
    ElseIf pprsrc = "Seller revert awaited" Then 
     ie.document.getElementById("pc-pitchInProgressRequestStatusReasonCode-edit").Click 
     ie.document.getElementById("pc-pitchInProgressRequestStatusReasonCode-input_3").Click 
     ie.document.getElementById("pc-pitchInProgressRequestStatusReasonCode-button").Click 
    ElseIf pprsrc = "products delayed" Then 
     ie.document.getElementById("pc-pitchInProgressRequestStatusReasonCode-edit").Click 
     ie.document.getElementById("pc-pitchInProgressRequestStatusReasonCode-input_4").Click 
     ie.document.getElementById("pc-pitchInProgressRequestStatusReasonCode-button").Click 
    End If 
    Dim nirsrc As Range   
    Set nirsrc = ThisWorkbook.Sheets("Dump").Range("M4") 
    If nirsrc = "" Then 
     nirsrc = "" 
    ElseIf nirsrc = "Pricing issues" Then 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-edit").Click 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-input_1").Click 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-button").Click 
    ElseIf nirsrc = "Using another SP" Then 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-edit").Click 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-input_2").Click 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-button").Click 
    ElseIf nirsrc = "In house capability" Then 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-edit").Click 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-input_3").Click 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-button").Click 
    ElseIf nirsrc = "No current requirement" Then 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-edit").Click 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-input_4").Click 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-button").Click 
    ElseIf nirsrc = "Non serviceable" Then 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-edit").Click 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-input_5").Click 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-button").Click 
    ElseIf nirsrc = "Not Applicable" Then 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-edit").Click 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-input_0").Click 
     ie.document.getElementById("pc-notInterestedRequestStatusReasonCode-button").Click 
    End If 
    Dim SM As Range  
    Set SM = ThisWorkbook.Sheets("Dump").Range("N4") 
    If SM = "" Then 
     SM = "" 
    Else 
     ie.document.getElementById("pc-salesManagerName-edit").Click 
     ie.document.getElementById("pc-salesManagerName-input").Value = SM 
     ie.document.getElementById("pc-salesManagerName-button").Click 
    End If 
    Dim Comments As Range   
    Set Comments = ThisWorkbook.Sheets("Dump").Range("O4") 
    If Comments = "" Then 
     Comments = "" 
    Else 
     ie.document.getElementById("pc-providerComments-edit").Click 
     ie.document.getElementById("pc-providerComments-input").Value = Comments 
     ie.document.getElementById("pc-providerComments-button").Click 
    End If 
    ie.document.getElementById("save-detail-btn-announce").Click 
Next i 

あなたが使用している「すなわち」オブジェクトを初期化していない場合End Subの

+4

*私はオプションを使用していません。明示的に* - それから始まります。また、エラーを投げているラインを教えてください。 –

+0

IF文から始まりその外側で終了するループがあります。あなたの最初の 'FOR EACH xx1'は' IF cellvalue'ブロックの終わりで終わります。....待って、いいえ...あなたのコードブロックをインデントして読みやすくしてください! –

+2

あなたのコードをインデントすると、誰もがそれをよく読んでより簡単に手助けできるようになるでしょう。 –

答えて

0

オブジェクトに必要なエラーが出てきます。 また、インデントされたコードは、このような少し見えるはずです。

Dim cellvalue As String 
cellvalue = "Pitch in Progress " 

If cellvalue = "" Then 
    cellvalue = "" 
ElseIf cellvalue = "Pitch in Progress " Then           '---------- Pitch in Progress -------- 
    ie.Document.getElementById("a-autoid-0-announce").Click 
    ie.Document.getElementById("dp-status-dropdown_0").Click 
    Dim xx1 As Object 
    For Each xx1 In ie.Document.getElementsByClassName("a-button-text") 
     If xx1.innerText Like "*OK*" Then 
     ' Debug.Print xx1.innerText 
      xx1.Click 
      Exit For 
     End If 
    Next xx1 
ElseIf cellvalue = "Not Reachable" Then          '--------- Not Reachable ----------- 
    ie.Document.getElementById("a-autoid-0-announce").Click 
    ie.Document.getElementById("dp-status-dropdown_1").Click 
    Dim xx2 As Object 
    For Each xx2 In ie.Document.getElementsByClassName("a-button-text") 
     If xx2.innerText Like "*OK*" Then 
      ' Debug.Print xx1.innerText 
      xx2.Click 
      Exit For 
     End If 
    Next xx2 
End If 

私は最後に、「あれば終了」、と私はcellvalueという変数を宣言し、それがコードを実行されるように、「進行中のピッチ」に設定し、エラーがあるしているが追加されている注意事項

ie.Document.getElementById("a-autoid-0-announce").Click 
+0

チャーンのため申し訳ありませんが、以下はコード全体です。私は以下の行でエラーが発生しています。 –

+0

ie.Document.getElementById( "a-autoid-0-announce")。 –

+0

をクリックしてください。私のコードは約750+行です。 –

関連する問題