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

asked on

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

Avatar of omgang
omgang
Flag of United States of America image

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
Avatar of karthik80c

ASKER

Yes I have checked the reference "Microsoft Internet Controls". I didn't try run the code manually.
ASKER CERTIFIED SOLUTION
Avatar of omgang
omgang
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