Solved

Excel Macro to read xml file from web

Posted on 2014-01-22
8
824 Views
Last Modified: 2014-01-28
Hi,

I have several workbooks that need to access an XML file called config.xml from a website, say website.co.uk, although all the workbooks access the same config.xml it needs to have independent sections for each of them, so I can define version numbers initially followed by other data later on...

Therefore, how do I create a excel macro that will access this file, and check version number so I can compare if its latest version, how would I access the individual workbook versions from the xml, and how would the xml be laid out?

Cheers
0
Comment
Question by:DemonForce
  • 4
  • 4
8 Comments
 
LVL 43

Expert Comment

by:Rob
ID: 39801982
Your XML would look something like this

<?xml version="1.0"?> 
<files>
    <file id="00413">
        <version>1.2.3</version>
        <title>Workbook about something</title>
    </file>
    .... // repeat multiple files as necessary
</files>

Open in new window


You'll have a better idea than me about what fields you'd need but I've started with 3: Version, Title and an ID attribute.  A numeric ID that is unique to the workbook is going to be the best way to compare and retrieve data for the workbook requesting it.

sample code to load the xml (need reference to MSXML library)
Sub xmlparse()
    Dim oDoc As New DOMDocument
    oDoc.async = False
    oDoc.validateOnParse = False
    fSuccess = oDoc.Load(ActiveWorkbook.Path & "\config.xml")
     
    MsgBox fSuccess
End Sub

Open in new window

0
 
LVL 43

Accepted Solution

by:
Rob earned 500 total points
ID: 39802018
Sample workbook loading the xml
xml.xlsm
config.xml
0
 

Author Comment

by:DemonForce
ID: 39809226
Seems perfect thank you for the examples, I assume by editing     fSuccess = oDoc.Load(ActiveWorkbook.Path & "\config.xml") I can get it to take the config.xml from any website?

Thanks
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 43

Expert Comment

by:Rob
ID: 39809247
That's correct. The load argument can either be a path or url
0
 

Author Comment

by:DemonForce
ID: 39809291
Ok, been playing around with it and have put more data into the xml, and have it loading the data on worksheet open, however...  When I load the sheet there is a delay as it is loading the data from the file in, and then nothing is displayed on screen until I call the routine from a button attached to the main macro.

It would appear to me that it is loading the data and continues into macro, as it currently does not have data the criteria is not matched so therefore does not show, until it is activated second time?
0
 

Author Comment

by:DemonForce
ID: 39809310
Right, took the ELSE out and it works perfect now, cheers.
0
 

Author Comment

by:DemonForce
ID: 39816024
Hi,

I downloaded and extensively modified your example that you supplied for reading in XML.  For some reason when I export the code, and import elsewhere I get an error related to this part...

Dim oDoc As DOMDocument

Compile error:

User-defined type not defined


Always works fine in supplied example.
0
 
LVL 43

Expert Comment

by:Rob
ID: 39816062
Did you add the reference to msxml?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA modules import 4 57
MS Excel Multi Sheet Formula 13 36
Create an Excel User-form to Display Filter Results - Modify Macro 10 30
Shape manipulation in Excel 2 20
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question