Link to home
Start Free TrialLog in
Avatar of karthik80c
karthik80cFlag for United States of America

asked on

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

Avatar of Kimputer
Kimputer

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)
ASKER CERTIFIED SOLUTION
Avatar of karthik80c
karthik80c
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of karthik80c

ASKER

Declared IE as object (SHDocVw.InternetExplorer)