View Single Post
 
Old 02-09-2024, 07:36 AM
Omar2008 Omar2008 is offline Windows 10 Office 2013
Novice
 
Join Date: Feb 2024
Location: Lima Perú
Posts: 6
Omar2008 is on a distinguished road
Default 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
Attached Images
File Type: png Ex05 current customs XML parts.png (49.1 KB, 12 views)
File Type: png Ex05macro xml 6.png (16.1 KB, 12 views)
Attached Files
File Type: docx Ex05.docx (20.3 KB, 3 views)
File Type: docm Ex05macro.docm (17.7 KB, 2 views)
File Type: zip Ex03Rev1.zip (741 Bytes, 3 views)
Reply With Quote