The script runs in outlook 2013 but not in outlook 2010

The following script runs well in outlook 2013, but it shows the run-time error "Object variable or With block variable not set" in "line 14" when runs on outlook 2010.

Sub PropertyURLL()

Dim IE As New InternetExplorer
IE.navigate "http://www.realcommercial.com.au/property-retail-qld-kooralbyn-501463555"

Do
DoEvents
Loop Until IE.readyState = READYSTATE_COMPLETE
Dim Doc As HTMLDocument
Set Doc = IE.document

Dim sDD As String

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 Variant
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
Title = dtInspDe

MsgBox sDD
MsgBox topic
MsgBox status
MsgBox body
MsgBox price
MsgBox Poost
MsgBox Title
MsgBox suburb
  
End Sub

Private Sub test(CurrentItem As Object)
    Dim currItem As MailItem
    
    Set currItem = ActiveInspector.CurrentItem
    PropertyURL currItem
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.

omgangIT ManagerCommented:
I don't have Outlook 2013 immediately available to test with but I did try the code in Outlook 2010.  Do you have a Reference, in Outlook 2013, for Microsoft Internet Controls?  Also, I added an Option Explicit statement at the top of my test module and you have a couple of undeclared variables
Dim dtInspDe As Variant, Title As Variant
but that should not cause the error you are getting.
Is it possible the code is processing too quickly?  Does it work if you set a break point and step through the code manually?
OM Gang
0
karthik80cAuthor Commented:
Yes I have checked the reference "Microsoft Internet Controls". I didn't try run the code manually.
0
omgangIT ManagerCommented:
When I run the routine in Outlook 2010 it completes successfully and displays a series of message boxes.

The second procedure doesn't compile and I've commented it for testing.
The call to the first procedure is misspelled (should be PropertyURLL) and is passing an argument/parameter when the procedure does not include any.

Private Sub test(CurrentItem As Object)
    Dim currItem As MailItem
    
    Set currItem = ActiveInspector.CurrentItem
    PropertyURL currItem
End Sub

Open in new window


I can't imagine this is the cause of the error you are receiving though.  Here's what I have in Outlook 2010 and it is working fine.

Option Explicit


Sub PropertyURLL()
On Error GoTo Err_PropertyURLL

    Dim IE As New InternetExplorer


    IE.navigate "http://www.realcommercial.com.au/property-retail-qld-kooralbyn-501463555"

    Do
        DoEvents
    Loop Until IE.readyState = READYSTATE_COMPLETE
    Dim Doc As HTMLDocument
    Set Doc = IE.Document

    Dim sDD As String

    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 Variant
    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 dtInspDe As Variant, Title 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
    Title = dtInspDe

    MsgBox sDD
    MsgBox topic
    MsgBox status
    MsgBox body
    MsgBox price
    MsgBox Poost
    MsgBox Title
    MsgBox suburb


Exit_PropertyURLL:
    Set topic = Nothing
    Set Doc = Nothing
    Set IE = Nothing
   Exit Sub

Err_PropertyURLL:
   MsgBox Err.Number & " (" & Err.Description & ") in procedure PropertyURLL of Module Module7"
   Resume Exit_PropertyURLL
  
End Sub

Private Sub test(CurrentItem As Object)
    'Dim currItem As MailItem
    
    'Set currItem = ActiveInspector.CurrentItem
    'PropertyURL currItem
End Sub

Open in new window



These are the references I have set.
References
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
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.