Solved

Excel Macro to read xml file from web

Posted on 2014-01-22
8
839 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

734 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