+ Reply to Thread
Results 1 to 10 of 10

Help! Import XML data into Excel hourly

Hybrid View

  1. #1
    Registered User
    Join Date
    01-23-2017
    Location
    Ohio
    MS-Off Ver
    2010
    Posts
    9

    Question Help! Import XML data into Excel hourly

    Hello,

    I need help with what should be a simple task, but I can't seem to figure it out. I need to take XML data from a thermostat device and paste it into an Excel spreadsheet. I can do this manually without issue, but I want this to be automated and done hourly.

    Here is what I want it to look like:

    First Column, first row: Insert current date and time
    Second Column, first row: import current XML data here

    Then, one hour later, I want it to drop to the next available row and repeat. When I have attempted to do this via Macros in Excel, it give me an error on the second attempt about overwriting the XML data. I don't need fancy charts or stylish formatting, just simple data scraping.

    Thanks in advance!

    Jon

  2. #2
    Registered User
    Join Date
    01-23-2017
    Location
    Ohio
    MS-Off Ver
    2010
    Posts
    9

    Re: Help! Import XML data into Excel hourly

    Here is an example of how I can do this once...

    https://youtu.be/KCvcHhEB9-8

  3. #3
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Help! Import XML data into Excel hourly

    Herés the modified code:

    Sub XML_Data_Macro()
    '
    ' XML_Data_Macro Macro
    '
    Dim lstRow  As Long '*  variable to hold the last row
    lstRow = Cells(Rows.Count, 1).End(xlUp).Row '*  find the last filled row
    If Len(Trim(Cells(lstRow, 1).Value)) > 0 Then lstRow = lstRow + 1  '*  if this is > 1 then add 1
    Cells(lstRow, 1).Value = Format(Now(), "dd/mm/yyyy hh:mm")      '*  place timestanp in column A
    Range("B" & lstRow).Select
    ActiveWorkbook.XmlImport URL:="C:\Users\Jon\Desktop\books.xml", ImportMap:= _
        Nothing, Overwrite:=True, Destination:=Range(Range("B" & lstRow))
    Cells.Columns.AutoFit
    End Sub
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  4. #4
    Registered User
    Join Date
    01-23-2017
    Location
    Ohio
    MS-Off Ver
    2010
    Posts
    9

    Re: Help! Import XML data into Excel hourly

    Here is the error I receive

    Capture.PNG

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Help! Import XML data into Excel hourly

    Record a macro while you're doing the actual importing and use the data from that macro and combine it with what I gave you, how hard can it get?

  6. #6
    Registered User
    Join Date
    01-23-2017
    Location
    Ohio
    MS-Off Ver
    2010
    Posts
    9

    Re: Help! Import XML data into Excel hourly

    I figured it out. There was an extra Range() in there:

    Sub XML_Data_Macro()
    '
    ' XML_Data_Macro Macro
    '
    Dim lstRow  As Long '*  variable to hold the last row
    lstRow = Cells(Rows.Count, 1).End(xlUp).Row '*  find the last filled row
    If Len(Trim(Cells(lstRow, 1).Value)) > 0 Then lstRow = lstRow + 1  '*  if this is > 1 then add 1
    Cells(lstRow, 1).Value = Format(Now(), "dd/mm/yyyy hh:mm")      '*  place timestanp in column A
    Range("B" & lstRow).Select
    ActiveWorkbook.XmlImport URL:="http://www.w3schools.com/xml/note.xml", _
            ImportMap:=Nothing, Overwrite:=True, Destination:=Range("B" & lstRow)
    Cells.Columns.AutoFit
    End Sub

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Help! Import XML data into Excel hourly

    You're getting the error becasue of this part and that's you responsability.

    The Url of file location

    ActiveWorkbook.XmlImport URL:=
    "C:\Users\Jon\Desktop\books.xml", ImportMap:= _
        Nothing, Overwrite:=True, Destination:=Range(Range("B" & lstRow))
    All I did was help you with the row
    I think you'll have to replace that section with the valid URL where you're getting the data from

  8. #8
    Registered User
    Join Date
    01-23-2017
    Location
    Ohio
    MS-Off Ver
    2010
    Posts
    9

    Re: Help! Import XML data into Excel hourly

    I don't have access to the exact source, since I am not at the site of the equipment. I was just using a local test .xml file, but I can use a web hosted sample file instead to make it simpler.

    http://www.w3schools.com/xml/note.xml

    Sub XML_Data_Macro()
    '
    ' XML_Data_Macro Macro
    '
    Dim lstRow  As Long '*  variable to hold the last row
    lstRow = Cells(Rows.Count, 1).End(xlUp).Row '*  find the last filled row
    If Len(Trim(Cells(lstRow, 1).Value)) > 0 Then lstRow = lstRow + 1  '*  if this is > 1 then add 1
    Cells(lstRow, 1).Value = Format(Now(), "dd/mm/yyyy hh:mm")      '*  place timestanp in column A
    Range("B" & lstRow).Select
    ActiveWorkbook.XmlImport URL:="http://www.w3schools.com/xml/note.xml", ImportMap:= _
        Nothing, Overwrite:=True, Destination:=Range(Range("B" & lstRow))
    Cells.Columns.AutoFit
    End Sub
    I still get the same error. Is the Range(Range part correct?

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Help! Import XML data into Excel hourly

    Sorry my mistake:

    Sub XML_Data_Macro()
    '
    ' XML_Data_Macro Macro
    '
    Dim lstRow  As Long '*  variable to hold the last row
    lstRow = Cells(Rows.Count, 1).End(xlUp).Row '*  find the last filled row
    If Len(Trim(Cells(lstRow, 1).Value)) > 0 Then lstRow = lstRow + 1  '*  if this is > 1 then add 1
    Cells(lstRow, 1).Value = Format(Now(), "dd/mm/yyyy hh:mm")      '*  place timestanp in column A
    Range("B" & lstRow).Select
    ActiveWorkbook.XmlImport URL:="http://www.w3schools.com/xml/note.xml", ImportMap:= _
        Nothing, Overwrite:=True, Destination:=Range("B" & lstRow)
    Cells.Columns.AutoFit
    End Sub

  10. #10
    Registered User
    Join Date
    01-23-2017
    Location
    Ohio
    MS-Off Ver
    2010
    Posts
    9

    Re: Help! Import XML data into Excel hourly

    Thank you very much for your help. I just now need this to be automated hourly. I believe I can do this with Task Scheduler. If you have any insights into that portion, feel free to offer suggestions.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How do I add a number from each Hourly data to 1/4 hourly about 8,000 times?
    By Louis59 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-26-2014, 01:02 AM
  2. Import TXT files from a specific folder into Excel - TXT file names change hourly
    By jeepinjeff in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-16-2013, 04:08 AM
  3. Import web data into excel does not import picture, how to substitute picture for a value
    By anrichards22 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-19-2012, 03:29 AM
  4. [SOLVED] Splitting hourly data into 1/4 hourly data
    By freethinker in forum Excel - New Users/Basics
    Replies: 8
    Last Post: 11-09-2012, 08:01 AM
  5. Replies: 5
    Last Post: 09-11-2012, 03:45 PM
  6. Hourly data
    By liawsiqin@gmail in forum Excel General
    Replies: 2
    Last Post: 12-22-2010, 03:33 PM
  7. Replies: 1
    Last Post: 11-08-2010, 02:15 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1