4

I'm trying to create an XML file from VBA found in Excel, I'm a little hazy on the details though, I've never touched XML or VBA before in my life. I need to write out an XML file with in the following format:

<TextField0 xfdf:original="Brand Name">HEADING1</TextField0>

There will be a bunch of lines like this such as TextField1, which is "Product" and so on. The code I have thus far revelent to this section is this:

   'create Heading element
   Set objXMLelement = objDom.createElement("TextField0")
   objXMLRootelement.appendChild objXMLelement

   'create Attribute to the Heading Element and set value
   Set objXMLattr = objDom.createAttribute("xfdf:original")
   objXMLattr.NodeValue = "Brand Name"
   objXMLelement.setAttributeNode objXMLattr

That creates this output:

<TextField0 xfdf:original="Brand Name"/>

This is of coursem missing HEADING1 and I can't for the life of me figure out how to put that bit in there. I can't seem to append anything to an attribute. Any help will be gratefully received.

1 Answer 1

5

HEADING1 is the text that belongs to the TextField0 element, not the attribute.

So you can set it using the objXmlElement.text property.

In response to comment:

I'm struggling to find documentation for this stuff

This MSDN page is a good start.

Sign up to request clarification or add additional context in comments.

2 Comments

Wow. How simple! Thanks a lot, I'm struggling to find documentation for this stuff.
Many thanks for the link to the "Program with DOM in Visual Basic" tutorial on MSDN - very helpful indeed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.