Sub SmartDocs_UpdateReusableVariable(variableName As String, variableValue As String) Dim namespaceUri As String namespaceUri = "http://www.thirtysix.net/smartdocs/reusableVariables" ' Get the custom XML part that contains SmartDocs reusable variables. Dim xmlPart As CustomXMLPart Set xmlPart = ActiveDocument.CustomXMLParts.SelectByNamespace(namespaceUri)(1) ' Ensure custom XML part was found. If xmlPart Is Nothing Then Exit Sub End If ' Get prefix for namespace. Dim prefix As String prefix = xmlPart.NamespaceManager.LookupPrefix(namespaceUri) ' Create XPath to XML node that contains SmartDocs reusable variable. Dim xpath As String xpath = "//{prefix}:ReusableVariable[{prefix}:Name='{name}']/{prefix}:Value" xpath = Replace(xpath, "{prefix}", prefix) xpath = Replace(xpath, "{name}", variableName) ' Get the XML node. Dim xmlNode As CustomXMLNode Set xmlNode = xmlPart.DocumentElement.SelectSingleNode(xpath) If xmlNode Is Nothing Then Exit Sub End If ' Update the value of the node. xmlNode.Text = variableValue End Sub