Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Thanked 0 Times in 0 Posts

    XML from Word (Win XP / O2003)


    So far I've been using INI files to store user preferences in... - however looking ahead I can see the advantages of XML in general.
    - so to build for the future I would appreciate if someone has a simple example on how I get a user preference or setting into an XML file and also how I read it back in.

    ex. Would like to prompt user for some info - let's say "department" and "job title", user types in a dialog box.
    Subsequently store this in an XML file and later read the data.

    Any hints are appreciated - tia

    PS: Wish there were a knob on the TV to turn up the intelligence. There's a knob called "brightness," but that doesn't work

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 94 Times in 90 Posts

    Re: XML from Word (Win XP / O2003)

    The way I've used XML probably is not the easiest, but I was throwing it together without a really good reference. See <post#=343644>post 343644</post#> for an example. There I create a little structured document storing information on Outlook CommandBars (position, etc.) so that after add-ins mess up my toolbars I can reposition where I want them with one click.

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Melbourne, Victoria, Australia
    Thanked 295 Times in 267 Posts

    Re: XML from Word (Win XP / O2003)

    I guess that it depends on which version of Word you are using as to which is the easiest way to do this. The following function is the one I created for using in Word 2002 to populate a combobox in a Word document from an existing XML doc. At the time I was only reading XML files and not writing to them. I suspect that writing out as XML is easier now if you are using Word 2003. If you use some of the keywords found in this code and do some searches (probably other than on the lounge) you should find some sample code to build and read your ini settings.

    You may need to add a reference to Microsoft XML v5.0 or later for setting up the intellisense for playing around in the code.
    <pre>Public Function funFillList(ctlList As ComboBox)
    Dim xmlSource As Object
    Dim wholeXML As Object
    Dim n As Integer

    On Error GoTo HandleErr
    'clear current contents
    ctlList.Clear 'calls the change event

    Set xmlSource = CreateObject("MSXML2.DOMDocument")
    xmlSource.validateOnParse = True
    xmlSource.async = False
    xmlSource.Load (funPathToData & sRolesFile)
    Set wholeXML = xmlSource.getElementsByTagName("position/@title")
    Debug.Print "There are " & wholeXML.Length & " roles in the file"

    For n = 0 To wholeXML.Length - 1
    Debug.Print wholeXML(n).Text
    ctlList.AddItem wholeXML(n).Text
    Next n

    Exit Function

    MsgBox "Error " & Err.Number & ": " & Err.Description
    Resume ExitHere
    End Function</pre>

    Andrew Lockton, Chrysalis Design, Melbourne Australia

Posting Permissions

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