0

I m new to VBA and need help with this. Can someone please help. When i execute, i m getting Object required. I not using Option Explicit. Thank You.

Getting error in the below line.

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

Have posted most of the code. Please help.

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
  • 4
    I['m] not using Option Explicit - then start with that. Also, mind telling us which line is throwing the error? Commented Oct 17, 2017 at 16:10
  • 1
    You've got a loop starting in an IF statement and ending outside it. Your first FOR EACH xx1 starts in the IF cellvalue block end ends just outside it.... wait, no it doesn't... indent your code blocks for readability! Commented Oct 17, 2017 at 16:27
  • 2
    Indenting your code might help everyone read it better and be able to help easier. Commented Oct 17, 2017 at 16:27
  • I think you should have an END IF after your last NEXT xx2. But as @Mat'sMug said - please select Tools ~ Options ~ Require Variable Declaration to get Option Explicit at the top of each new module. Commented Oct 17, 2017 at 16:31

1 Answer 1

0

Object required error will come up if you have not initialized the "ie" object you are using. Also, the indented code should look a little something like this.

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

Note that I have added an "End if" in the end, and I have declared a variable called cellvalue and set it to "Pitch in Progress " so that it runs through the code, and the error is thrown on this line:

ie.Document.getElementById("a-autoid-0-announce").Click
Sign up to request clarification or add additional context in comments.

7 Comments

Sorry for the churn, below is the entire code. I am getting error in the below line.
ie.Document.getElementById("a-autoid-0-announce").Click
If you add just the Sub or function where this piece belongs, it would be very helpful. If 750+ lines is just one Sub, you should consider separating that. It will be really hard to maintain this in the future.
Thank you Alvaro. For all the comments. I have Edited the original post, could you please help in resolving this error.
I am currently at work with very limited internet connection, and I have never used this functionality to connect with IE before. When I get home, I will try to check up on this and get back to you
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.