Results 1 to 8 of 8
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA or MSXML to read a .xml file (WordXP)

    Ive been asked to convert the VBA code that reads the .ini files , to use VBA or MSXML to read a .xml file.

    We currently have WordXP. We wont be going to Office2003 in the near future. therefore it has to be in OfficeXP.
    Ive had a look on the MSDN.

    I have no idea where to start?
    I dont even know if it can be done in WOrdXP.
    any ideas? or sample code I can use as a reference starting point?
    diana

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: VBA or MSXML to read a .xml file (WordXP)

    Hi Diana,
    You could try downloading the MSXML SDK from MSDN or just set a reference to MSXML in Word VBA and examine the library in the object browser. As a rough example, something like this should work:
    <pre> Dim objXML As New MSXML2.DOMDocument
    Dim objXMLNode As MSXML2.IXMLDOMNode

    'Load the document into the MSXML parser.
    objXML.Load "pathandfilename.xml"

    'Select the node you want to modify and assign the new value.
    Set objXMLNode = objXML.selectSingleNode(querystring:=nodenamehere)
    strValue = objXMLNode.nodeTypedValue
    </pre>

    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VBA or MSXML to read a .xml file (WordXP)

    While it is more work to write XML read/write code, and the documentation is not very step-by-step for small applications like this, you can consult some samples. Here's one I posted on the Outlook board: Re: Locking toolbars? (XP). If you run the macro and then look at the .xml file in Internet Explorer (where by default you get a nicely indented layout) you can see how it is a somewhat self-documenting, text-y representation of a exactly what you might store in a database or spreadsheet.

    Added: You will notice that my sample won't give you nice object/method/property prompts. I used "early binding" to develop this module, so I did have the benefits of having a type library at that time (I added the library to my References list). However, when I finalized the procedure, I changed it to "late binding" by using generic objects so that the library reference was not needed. This was both to make it easier for others to install and to eliminate any dependency on the specific version of MSXML on the user's machine. Makes my life easier. <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15> However, if you decide to use advanced features of a more recent library, then you might have to use early binding.

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA or MSXML to read a .xml file (WordXP)

    Thanks for that Rory I'll take a look at that code.

    I took alook at MSDN & some of the sample code. (I found I was getting really lost [img]/forums/images/smilies/ohmy.gif[/img]) )

    cheers diana

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA or MSXML to read a .xml file (WordXP)

    Thanks Jefferson.

    I did search Woody & found & read your sample & Andrews code - both good.

    I was having trouble trying to get the code working - (it think i was in such an .XML fluster & needed a break from it all [img]/forums/images/smilies/ohmy.gif[/img])

    Will tackle it again tomorrow
    diana :-)

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: VBA or MSXML to read a .xml file (WordXP)

    I wonder why there are so many uses of Call in that code? Is Call implicit whenever one uses a method? I don't know whether it is a good coding practice to use Call in those cases or ???

  7. #7
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Melbourne, Australia
    Posts
    1,294
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA or MSXML to read a .xml file (WordXP)

    (Edited by HansV to make URL clickable - see <!help=19>Help 19<!/help>)

    Hello

    I found some code on the web which is applicable that I understand. See attachment
    http://groups.google.co.uk/group/microsoft...c8f73ad9971fd89

    Note: to get the code working in VBA - I added the reference Microsoft XML. v3.0
    cheers diana <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  8. #8
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VBA or MSXML to read a .xml file (WordXP)

    > I don't know whether it is a good coding practice to use Call
    Well, we can't argue with an MS MVP <img src=/S/wink.gif border=0 alt=wink width=15 height=15>, but I say get rid of all of the Call's.
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

Posting Permissions

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