I got run time error in Outlook VBA script

It shows
Run-time error '91' - Object variable or With block variable not set
in line number 36 on the below code.

Sub PropertyURL(itm As MailItem)

    Dim bodyString As String
    Dim bodyStringSplitLine
    Dim bodyStringSplitWord
    Dim splitLine
    Dim splitWord
    Dim pageurl As String
    Dim checkdup

    bodyString = itm.body
    bodyStringSplitLine = Split(bodyString, vbCrLf)
MsgBox "Property"
    For Each splitLine In bodyStringSplitLine
        bodyStringSplitWord = Split(splitLine, "http://")

        For Each splitWord In bodyStringSplitWord
        
            If Left(splitWord, 34) = "www.realcommercial.com.au/property" Then
pageurl = Left(splitWord, Len(splitWord) - 2)
MsgBox pageurl
If pageurl Like "*>*" Then
pageurl = "hi"
MsgBox "no"
ElseIf pageurl <> checkdup Then
Dim IE As New InternetExplorer
IE.navigate pageurl
IE.Visible = True
Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Dim Doc As HTMLDocument
Set Doc = IE.Document

Dim sDD As Variant
sDD = Trim(Doc.getElementsByTagName("h1")(0).innerText)
Dim Topic As MSHTML.IHTMLElement
Set Topic = Doc.getElementById("description")
Debug.Print Topic.innerHTML
Dim status As Variant
status = Doc.getElementsByClassName("saleType")(0).innerText
Dim body As String
body = Doc.getElementsByClassName("body")(0).innerText
Dim price As Variant
price = Doc.getElementsByClassName("price ellipsis")(0).innerText

 Dim dtInspDate As Variant
 Dim dtInspTime As Variant
 Dim aTextTmp As Variant, aInspDate As Variant

aInspDate = Split(sDD, ", ")
dtInspDate = aInspDate(1)
dtInspDe = aInspDate(0)

Dim Poost As String
Poost = Right(sDD, 4)
Dim suburb As String
suburb = dtInspDate
Dim Title As String
Title = dtInspDe
Dim url As String
body = Replace(body, "&", " and ")
MsgBox body
MsgBox Poost
MsgBox pageurl
MsgBox Title


checkdup = pageurl

End If
End If

  
        Next

    Next
Set checkdup = Nothing
    Set itm = Nothing

End Sub

Open in new window

karthik80cAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KimputerCommented:
I'm still just about sure there's no h1 html tag on your page.
Change it to meta or body, and you will see the code jumps passed it (although it's not what you want, it's just to demonstrate my point)
0
karthik80cAuthor Commented:
Use
Dim IE As SHDocVw.InternetExplorer
 Set IE = New SHDocVw.InternetExplorer

Open in new window

instead of
Dim IE As New InternetExplorer

Open in new window

Full Code
Sub PropertyURL(itm As MailItem)

Dim bodyString As String
Dim bodyStringSplitLine
Dim bodyStringSplitWord
Dim splitLine
Dim splitWord
Dim pageurl
Dim url
Dim checkdup
bodyString = itm.body
bodyString = Replace(bodyString, "%3a%2f%2f", "://")
bodyString = Replace(bodyString, "%3f", "?")
bodyString = Replace(bodyString, "%2f", "/")
bodyStringSplitLine = Split(bodyString, vbCrLf)
For Each splitLine In bodyStringSplitLine
    bodyStringSplitWord = Split(splitLine, "http://")
    For Each splitWord In bodyStringSplitWord
   pageurl = Split(splitWord, "?")
        For Each url In pageurl
        
        If Left(url, 34) = "www.realcommercial.com.au/property" Then
            
            If url <> checkdup Then
            Dim IE As SHDocVw.InternetExplorer
            Set IE = New SHDocVw.InternetExplorer
            IE.navigate url
            IE.Visible = False
            
            Do
            DoEvents
            Loop Until IE.readyState = READYSTATE_COMPLETE
            Dim Doc As HTMLDocument
            Set Doc = IE.Document
            Dim sDD As Variant
            sDD = Trim(Doc.getElementsByTagName("h1")(0).innerText)
            Dim status As Variant
            status = Doc.getElementsByClassName("saleType")(0).innerText
            Dim body As String
            body = Doc.getElementsByClassName("body")(0).innerText
            Dim price As Variant
            price = Doc.getElementsByClassName("price ellipsis")(0).innerText
            Dim dtInspDate As Variant
            Dim dtInspTime As Variant
            Dim aTextTmp As Variant, aInspDate As Variant
            aInspDate = Split(sDD, ", ")
            dtInspDate = aInspDate(1)
            dtInspDe = aInspDate(0)
            Dim Poost As String
            Poost = Right(sDD, 4)
            Dim suburb As String
            suburb = dtInspDate
            Dim Title As String
            Title = dtInspDe
            body = Replace(body, "&", " and ")
            Dim Topics As IHTMLElementCollection
            Dim Topic As IHTMLElement
            Dim toppiicc
            Set Topics = Doc.getElementsByTagName("h3")
            For Each Topic In Topics
                If Topic.innerText <> "Be the first to see new properties" And Topic.innerText <> "Interested in this property? Contact an Agent today" And Topic.innerText <> sDD And Topic.innerText <> toppiicc Then
                toppiicc = Topic.innerText
               
                End If
            Next
            toppiicc = Replace(toppiicc, "&", " and ")
            Msgbox Title
     Msgbox body
            
            checkdup = url
            End If
        End If
        Next
    Next
Next
Set checkdup = Nothing
Set itm = Nothing
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
karthik80cAuthor Commented:
Declared IE as object (SHDocVw.InternetExplorer)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.