View Single Post
 
Old 11-21-2012, 02:52 PM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Probably better is to use SelectbyID:

PHP Code:
Sub DemoXX()
Dim oDoc As Word.Document
Dim oCustXMLPart As Office.CustomXMLPart
  Set oDoc = ActiveDocument
  'Kill any existing XMLPart used previously for demo.
  On Error Resume Next
    oDoc.CustomXMLParts.SelectByID(ActiveDocument.Variables("Part_ID")).Delete
  On Error GoTo 0
  'Create a basic XML Part with namespace.
  Set oCustXMLPart = ActiveDocument.CustomXMLParts.Add("<?xml version='1.0' ?><data xmlns='comments' xmlns:a='applicant'><a:Applicant><a:FullName>AEP Texas Central Company</a:FullName><a:AbbrName></a:AbbrName><a:DateFiled></a:DateFiled><a:Description></a:Description></a:Applicant></data>")
  'Store the ID value
  ActiveDocument.Variables("Part_ID").Value = oCustXMLPart.ID
  Set oCustXMLPart = Nothing
  RetrieveNodeData
End Sub
Sub RetrieveNodeData()
Dim oCustomXMLPart As CustomXMLPart
Dim oNode As CustomXMLNode
  Set oCustomXMLPart = ActiveDocument.CustomXMLParts.SelectByID(ActiveDocument.Variables("Part_ID"))
  'Or
  'Set oCustomXMLPart = ActiveDocument.CustomXMLParts.SelectByNamespace("comments").Item(1)
  Set oNode = oCustomXMLPart.SelectSingleNode("ns0:data[1]/ns1:Applicant[1]/ns1:FullName[1]")
  MsgBox oNode.Text
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote