Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 02-09-2024, 10:54 AM
Italophile Italophile is offline Convert XML to Word(Content Control) Windows 11 Convert XML to Word(Content Control) Office 2021
Expert
 
Join Date: Mar 2022
Posts: 554
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

I have not previously worked with custom xml parts with multiple records, so this has been a fun challenge.

The following code should get you most of the way there, though I can't guarantee that it will work in Office 2013:

Code:
Sub Ex05macro()
    Dim myDoc As Document: Set myDoc = Documents.Add
    Dim myXPart As CustomXMLPart: Set myXPart = myDoc.CustomXMLParts.Add
    Dim xNode As CustomXMLNode, xChild As CustomXMLNode
    Dim cc As ContentControl
    With myXPart
        .Load ("D:\Ex03Rev1.xml")
        For Each xNode In .DocumentElement.ChildNodes
            If xNode.HasChildNodes Then
                For Each xChild In xNode.ChildNodes
                    With xChild
                        If Not .BaseName = "#text" Then
                            Set cc = myDoc.ContentControls.Add(Type:=wdContentControlText, Range:=myDoc.Characters.Last)
                            cc.XMLMapping.SetMapping .XPath
                            myDoc.Paragraphs.Add
                        End If
                    End With
                Next xChild
                myDoc.Characters.Last.InsertBreak WdBreakType.wdPageBreak
            End If
        Next xNode
    End With
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adjust content antd line spacing in word table according to checkbox content control state AVarg123 Word VBA 13 01-10-2024 03:36 PM
Convert XML to Word(Content Control) Change Value of a Content Control based on the value of another content Control jsc_msoffice Word VBA 2 05-21-2021 09:51 PM
Convert XML to Word(Content Control) Content Control Dropdowns - How to duplicate the content control and allow a second choice ashleyf Word VBA 2 03-19-2020 09:11 AM
Convert XML to Word(Content Control) Clicking the selected Content Control checkbox returns wrong control in vba event DougsGraphics Word VBA 2 06-24-2015 07:31 AM
Convert XML to Word(Content Control) Deleting a table from a content control -- preserving the content control BrainSlugs83 Word Tables 8 11-14-2013 03:06 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:55 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft