G
Greg Maxey
I am trying to map a contentcontrol to the content of a
CustomDocumentProperty. With some help found here I have managed to create
a CustomXMLPart that contains the XML found in the docProps\custom.xml
folder. What I can't seem to get worked out is how to map to that data.
The following code will successfully map to a "BuiltInDocumentProperty" and
gives indications that it maps to a "CustomDocumentProperty." However, the
CC does not reflect the data in the CustomDocumentProperty after being
mapped.
Sub MapCCToCustomDocProperty()
Dim objcc As ContentControl
Dim objNode As CustomXMLNode
Dim blnMap As Boolean
Set objcc = ActiveDocument.ContentControls.Add(wdContentControlText,
Selection.Range)
'This works
'Set objNode = ActiveDocument.CustomXMLParts.SelectByNamespace _
'
("http://schemas.openxmlformats.org/package/2006/metadata/core-properties")
_
' (1).DocumentElement.ChildNodes(1)
'But this doesn't
Set objNode =
ActiveDocument.CustomXMLParts.SelectByNamespace("http://schemas.openxmlformats.org/"
_
&
"officeDocument/2006/custom-properties")(1).DocumentElement.ChildNodes(1)
Debug.Print objNode.XML
blnMap = objcc.XMLMapping.SetMappingByNode(objNode)
If blnMap Then
MsgBox "Eureka"
Else
MsgBox "Unable to map the content control."
End If
End Sub
This is the result of the Debug.Print objNode.XML:
<property
xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"
fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="2"
name="Client"><vt:lpwstr
xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">Smithg</vt:lpwstr></property>
From all indications that I see, it seems that my CC should show "Smithg"
after being mapped. What am I missing?
CustomDocumentProperty. With some help found here I have managed to create
a CustomXMLPart that contains the XML found in the docProps\custom.xml
folder. What I can't seem to get worked out is how to map to that data.
The following code will successfully map to a "BuiltInDocumentProperty" and
gives indications that it maps to a "CustomDocumentProperty." However, the
CC does not reflect the data in the CustomDocumentProperty after being
mapped.
Sub MapCCToCustomDocProperty()
Dim objcc As ContentControl
Dim objNode As CustomXMLNode
Dim blnMap As Boolean
Set objcc = ActiveDocument.ContentControls.Add(wdContentControlText,
Selection.Range)
'This works
'Set objNode = ActiveDocument.CustomXMLParts.SelectByNamespace _
'
("http://schemas.openxmlformats.org/package/2006/metadata/core-properties")
_
' (1).DocumentElement.ChildNodes(1)
'But this doesn't
Set objNode =
ActiveDocument.CustomXMLParts.SelectByNamespace("http://schemas.openxmlformats.org/"
_
&
"officeDocument/2006/custom-properties")(1).DocumentElement.ChildNodes(1)
Debug.Print objNode.XML
blnMap = objcc.XMLMapping.SetMappingByNode(objNode)
If blnMap Then
MsgBox "Eureka"
Else
MsgBox "Unable to map the content control."
End If
End Sub
This is the result of the Debug.Print objNode.XML:
<property
xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"
fmtid="{D5CDD505-2E9C-101B-9397-08002B2CF9AE}" pid="2"
name="Client"><vt:lpwstr
xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">Smithg</vt:lpwstr></property>
From all indications that I see, it seems that my CC should show "Smithg"
after being mapped. What am I missing?