Convert XML to Word(Content Control)
Good morning:
I am trying to convert XML file into Content Controls (Word)
Each record in different pages
XML file D:\Ex03Rev1.xml (zip file)
The prototype word file with the content controls is:
D:\Ex05.docx which which has 3 current custom XML parts
attachment: ("Ex05 current customs XML parts.png")
Win 2010 & Office 2013 with Ms XML 6.0
attachment: ("Ex05macro xml 6.png")
The code is in Ex05macro.docx
The code can not add xml part to the word file, then the following is not possible (link each record to content control
By other side, my understanding of XML 6.0 is limited. I don't know where, in the code, the number 4 corresponding to the new custom xml should go.
Please your help
thank
Omar
Sub Ex05macro()
' Dim xmlDoc As MSXML2.DOMDocument60
' Set xmlDoc = New MSXML2.DOMDocument60
' xmlDoc.Load ("d:\Ex03Rev1.xml")
' xmlDoc.async = False
' Dim docXML As IXMLDOMNode ' Define miNodo como IXMLDOMNode para la iteración
'Set docXML = New MSXML2.DOMDocument60
'Set docXLM = GetXMLDocument()
Dim myDoc As Document
Set myDoc = Documents.Open("d:\Ex05.docx")
myDoc.CustomXMLParts.Add
myDoc.CustomXMLParts(4).Load ("d:\Ex03Rev1.xml")
Debug.Print myDoc.CustomXMLParts(4).Errors
' For Each miNodo In xlmDoc.SelectNodes("//RECORD")
' myDoc.Selection.InsertBreak Type:=wdPageBreak
Dim strXPath As String
strXPath = "/RECORD/ID"
myDoc.ContentControls(1).XMLMapping.SetMapping strXPath
strXPath = "/RECORD/ONR"
myDoc.ContentControls(2).XMLMapping.SetMapping strXPath
strXPath = "/RECORD/TAREA"
myDoc.ContentControls(3).XMLMapping.SetMapping strXPath
strXPath = "/RECORD/RECURSOS"
myDoc.ContentControls(4).XMLMapping.SetMapping strXPath
strXPath = "/RECORD/PRIORIDAD"
myDoc.ContentControls(5).XMLMapping.SetMapping strXPath
strXPath = "/RECORD/AERODROMO"
myDoc.ContentControls(6).XMLMapping.SetMapping strXPath
strXPath = "/RECORD/ESTATUS"
myDoc.ContentControls(7).XMLMapping.SetMapping strXPath
' Next miNodo
myDoc.SaveAs "d:\Ex05ONR.docx"
myDoc.Close
' Set xmlDoc = Nothing
End Sub
|