Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-06-2017, 06:51 AM
slaycock slaycock is offline Problem adding a namespace for customxml Windows 7 64bit Problem adding a namespace for customxml Office 2013
Expert
Problem adding a namespace for customxml
 
Join Date: Sep 2013
Posts: 255
slaycock is on a distinguished road
Default Problem adding a namespace for customxml

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
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem batch adding autotext using Greg Maxey's Building Blocks Add-In Genuine Gin Word VBA 5 12-16-2015 10:20 AM
Problem Sending Command to the Program - Office or Windows Problem ?? JosieNurse Office 0 04-21-2015 11:49 AM
Problem adding a namespace for customxml Problem with Resolution when adding a picture in 2010 Zimm PowerPoint 1 11-13-2013 12:15 PM
Problem adding a namespace for customxml Problem with adding a footnote in Word Swarles_Barkley Word 1 11-12-2013 11:42 PM
Problem adding a namespace for customxml Adding Image into a excel cell and adding a hyperlink to the image saravananiyyanar Excel 3 05-04-2011 08:31 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:47 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft