I'm trying to create a namespace in athe Custom XML part of a Word document.
I've done extensive googling but good documentation is thin to non-existent.
The following code is extracted from Microsoft's help pages on CustomXMLPrefixMappings
Code:
Sub addXMLNamespaceTest()
' https://msdn.microsoft.com/en-us/library/office/ff863518.aspx
Dim objNamespace As CustomXMLPrefixMapping
objNamespace = CustomXMLPrefixMappings.AddNamespace(Prefix:="xs", NamespaceURI:="urn:invoice:namespace")
End Sub
but this gives a runtime error of object required and I can't figure out why.
A similar example found under the 'addnamespace' help (You have to add the XML to the CustomXMLPrefixMappings
https://msdn.microsoft.com/en-us/lib...ffice.15).aspx
Code:
Sub AddNamespacePrefix()
Dim objCustomPrefixMappings As CustomXMLPrefixMappings
Dim varCustomMapping As Variant
' Adds a custom namespace.
varCustomMapping = objCustomPrefixMappings.AddNamespace("xs", "urn:invoice:namespace")
End Sub
Highlights the addNamespace term with the error 'Function or variable required'.
Can anyone assist with the correct syntax for adding a namespace.
If it helps I've tried the code below (with reference to
https://www.w3schools.com/xml/xml_namespaces.asp )
and the xml parts are added under (no namespace) (1) and (no namespace (2) hence the investigation of .addNamsespace.
Code:
Sub testxmladd()
ActiveDocument.CustomXMLParts.add XML:= _
"<RCDP xmlns:a=""https://www.w3schools.com/furniture"">" & _
"<a:arcprop id=""HeadingVisibilityP"">" & _
"<a:visibility>True</a:visibility>" & _
"<a:enabled>True</a:enabled>" & _
"</a:arcprop>" & _
"<a:arcprop id= ""HeadingVisibilityS"">" & _
"<a:visibility>False</a:visibility>" & _
"<a:checked>True></a:checked>" & _
"</a:arcprop>" & _
"</RCDP>"
ActiveDocument.CustomXMLParts.add XML:= _
"<RCDP xmlns:a=""https://www.w3schools.com/furniture"">" & _
"<a:arcprop id=""HeadingVisibilityA"">" & _
"<a:visibility>True</a:visibility>" & _
"<a:enabled>True</a:enabled>" & _
"</a:arcprop>" & _
"<a:arcprop id= ""HeadingVisibilityR"">" & _
"<a:visibility>False</a:visibility>" & _
"<a:checked>True></a:checked>" & _
"</a:arcprop>" & _
"</RCDP>"
End Sub