user24
user24

Reputation: 75

GetElementByID from HTML to Excel failure

Can anyone help me with this vbscript? Trying to pull a value from IE to Excel using getelementbyID, but script only transfers [object HTMLDivElement] to Excel.

Set objExplorer = CreateObject("InternetExplorer.Application")
WebSite = "https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=abbott+stocks"
Const READYSTATE_COMPLETE = 4
WScript.Sleep 1000
With objExplorer
    .Navigate2 WebSite
    .Left=5
    .Top=5
    .Height=1000
    .Width=700
    .AddressBar = 0
    .Visible = 1
    .ToolBar = 0
    .StatusBar = 0
    Do Until .ReadyState = READYSTATE_COMPLETE
    Loop
End With

Set xl = CreateObject("Excel.Application")
    xl.Visible = True
Set wb = xl.Workbooks.Open("C:\Users\ukristense\Documents\CI\testauto.xlsx")
Set ws = wb.Sheets("Sheet1")
WScript.Sleep 5000

ws.Range("A1").Value = objExplorer.document.getElementById("resultStats")

WScript.Sleep 5000

objExplorer.Quit

Upvotes: 0

Views: 162

Answers (1)

Jordan
Jordan

Reputation: 4514

You're trying to set an object as a value, you will need to take the innerText, outerText, outerHTML or innerHTML based on your needs:

ws.Range("A1").Value = objExplorer.document.getElementById("resultStats").innerText

Upvotes: 1

Related Questions