0
votes

I am creating an application that targets at converting existing xml documents of Word 2003 to DOCX by replacing Custom XML elements with Content Controls. I am using Interop assemblies + Word 2007 for this purpose as only Word 2007 can support Custom XML elements and Content Controls.

The approach proposed is as below: 1. Read the xml document 2. Save as DOCX. 3. Identify XMLNodes (Custom XML elements) from the DOCX file 4. Place new Content Controls in the range of XMLNodes /Mapping XMLNodes to Content Controls. 5. Remove XMLNodes.

I am finding issues when implementing the above. Issue is that in Step 4 mentioned above, all content controls added to the document are removed once the document is saved. This is because the document is saved in Word 2003 compatibility mode and Word 2003 doesn’t support Content Controls.

I have tried a lot to disable the compatibility mode but couldn’t achieve it.

Can anyone of you kindly suggest me some methods of doing it?

2

2 Answers

0
votes

I have also been trying to do what you are doing. Someone pointed out that you can use open xml to do

0
votes

Step 1 : Run the below word 2003 macro in the word 2003 document and save it.

'Word 2003 macro
Sub BookmarkUpdate()

  Dim objNode As XMLNode
    For Each objNode In ActiveDocument.XMLNodes
        objNode.Range.Bookmarks.Add (objNode.BaseName)
    Next
End Sub

Step 2 : Open the same document in word 2010 and run the below word 2010 macro and save it.

' Word 2010 macro
Sub CreateContentControl()
Dim name As String
For Each bk In ActiveDocument.Bookmarks
   Dim objcc As ContentControl
   Dim objRange As Range   
   ' Get the first paragraph as a range object.
   Set objRange = bk.Range
   ' Create a rich text content control.
   Set objcc = ActiveDocument.ContentControls.Add(wdContentControlRichText, objRange)  
   name = bk.name 
   objcc.Title = name
   objcc.Tag = name
 Next
End Sub