I' trying to write an xml file from Excel VBA using Microsoft XML 6.0. So far it works fine, except for some attributes. This is an excerpt from my code:
Dim block,knoten,subknoten, subknoten2 As MSXML2.IXMLDOMNode
Dim attribut, attribut2 As MSXML2.IXMLDOMAttribute
'...'
Set knoten = block.appendChild(.createNode(NODE_ELEMENT, "name", ""))
Set attribut = .createAttribute("id")
attribut.nodeValue = "Knotentext"
knoten.setAttributeNode attribut ' works fine so far '
Set subknoten = knoten.appendChild(.createNode(NODE_ELEMENT, "unterknoten", ""))
Set subknoten2 = subknoten.appendChild(.createNode(NODE_ELEMENT, "unterknoten2", ""))
subknoten2.nodeTypedValue = "Knotentext"
Set attribut = .createAttribute("id")
attribut.Value ="Attributstext"
subknoten2.setAttributeNode attribut ' this line creates an error, rest is ok
'...'
The last line leads to the Compiler message "Method or object not found" This fits with the fact that "setAttributeNode" is not in the selection list when entering subknoten2. But what's the difference to knoten? They have both been defined and created the same way. In the monitoring window (Überwachungsfenster) I see the following types: knoten: Variant/Object/IXMLDOMElement subknoten2: IXMLDOMNODE/IXMLDOMElement
Does anyone have an idea what's going on here and how I can attach an attribute to subknoten2? Thanks for your time...