Link to home
Start Free TrialLog in
Avatar of nava1000
nava1000

asked on

Adding attribute to xml custompart in docx Word document at run time using VBA

I am saving data included in Word document in XML format in the ActiveDocument.CustomXmlParts.
I can add node to the XML structure, using VBA code,  but I didn't succeed to add new attribute. I've search a lot but didn't find any reference to this.
Here is the code:

Set MyDoc = ActiveDocument
xml = "<Root><Cities><City id='1'>NY</City><City id='2'>Boston</City></Cities></Root>"
Set MyPart = MyDoc.CustomXMLParts.Add(xml)
    
Set ParentNode = MyPart.SelectSingleNode("//Root/Cities")
MyPart.AddNode ParentNode, "City", , , , "LA"

Open in new window


How to add a node at runtime with an attribute: <City id='3'>LA</City>

Thank you

Nava
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nava1000
nava1000

ASKER

Thank you very much.