Remove Word content controls & retain data

diana
3StarLounger
Posts: 279
Joined: 01 Jun 2010, 00:27

Remove Word content controls & retain data

Post by diana »

Were receiving documents containing content controls and would like to remove the content controls and retain the data.

is there easy way to view the content controls in one location and then goto the content control. For example the Bookmarks dialog lists all bookmarks in the document

I goto the Developer tab and click Design View. This turns on the content control tags. However I have to scroll through the document to identify the content controls. These are long documents are its possible a content control can be missed.

TIA

--dd

User avatar
HansV
Administrator
Posts: 78917
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Remove Word content controls & retain data

Post by HansV »

I don't know of a built-in way to do this, so I think you'll have to write a macro that loops through the content controls.
Best wishes,
Hans

User avatar
kdock
5StarLounger
Posts: 723
Joined: 21 Aug 2011, 21:01
Location: The beautiful hills of Western North Carolina

Re: Remove Word content controls & retain data

Post by kdock »

Diana, I've been working with content controls a lot lately. There is no one place to review all content controls with their content from within Word. There is a Word 2007 Content Control Toolkit from Microsoft that does allow you to do something like what you're suggesting, but only if controls are "mapped." Is there a reason you need to review each control for content? You can click in one of the content controls and tab from control to control through the whole document.

This is code I use to delete controls and leave content behind:

Code: Select all

Do While ActiveDocument.ContentControls.Count > 0
    For Each oCC In ActiveDocument.ContentControls
    If oCC.LockContentControl = True Then oCC.LockContentControl = False
    oCC.Delete False
Next
Loop
The "False" in the last line keeps the content from being removed. Use "True" if you want to delete both the control and the content.

HTH, Kim
"Hmm. What does this button do?" Said everyone before being ejected from a car, blown up, or deleting all the data from the mainframe.

User avatar
kdock
5StarLounger
Posts: 723
Joined: 21 Aug 2011, 21:01
Location: The beautiful hills of Western North Carolina

Re: Remove Word content controls & retain data

Post by kdock »

Diana, here's a quick follow-up. I said the Word 2007 Content Control Toolkit only reported mapped controls. Not true -- it will list all the content controls in a document, mapped or not.

However, it's not a perfect tool. It lists controls by ID (an internal number) and tag. Content controls don't have to have a title or tag property, or, more confusingly, they can be duplicated within a document. However, there's a feature in it that might get you part the way where you're going.
2007 toolkit with annotations.png
Click the tiny Word icon I highlighted just above the list. This opens the document in read-only mode, alongside the list of controls it found. You can click a control on the list and it should be highlighted in the document. HOWEVER, I've found that if the ID is a negative number, the toolkit won't find it. I don't know how the ID is assigned and can't tell why it's sometimes negative.

But it might help you because it does accurately report how many controls are in the document, and initially lists them in order of their appearance in the document. You can also rearrange the list to show controls by location (main doc, header, etc), type of control, and so on.

I got it from HERE, but I know CodePlex is shutting down. If you search for "Word Content Control Toolkit" you should find a proper download location, too.

Hope this helps you a little more... Kim
You do not have the required permissions to view the files attached to this post.
"Hmm. What does this button do?" Said everyone before being ejected from a car, blown up, or deleting all the data from the mainframe.

User avatar
Jay Freedman
Microsoft MVP
Posts: 1320
Joined: 24 May 2013, 15:33
Location: Warminster, PA

Re: Remove Word content controls & retain data

Post by Jay Freedman »

Greg Maxey has an add-in that will take care of this task and much more, dealing with content controls, document variables, document properties, and bookmarks. Download it from http://gregmaxey.com/word_tip_pages/cc_ ... addin.html.

On the Lists tab, after choosing the Content Controls option button, the list shows the titles of the controls in the document. The Content/Value panel shows the current contents of the selected control. The Delete button removes the control and leaves the content as text.
1.png
You do not have the required permissions to view the files attached to this post.

User avatar
Charles Kenyon
5StarLounger
Posts: 641
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Remove Word content controls & retain data

Post by Charles Kenyon »

I am a regular user of Greg's Content Control Tools.
http://gregmaxey.com/word_tip_pages/con ... tools.html
They are easy to use and very helpful. If I want to do anything more than simply insert one-of content controls or use the Document Property Content Controls, that is my go-to resource.
Last edited by Charles Kenyon on 05 Feb 2018, 13:44, edited 1 time in total.

jec1
NewLounger
Posts: 9
Joined: 04 Nov 2013, 09:26

Re: Remove Word content controls & retain data

Post by jec1 »

Hi Diana

I use the below code. Greg's addin obviously does the same but the below macros do the job in legal documents I use. I have the macro on a global Word addin:

Code: Select all

Sub Finish_CCs()
'For all content controls throughout the document:
Call ccs_Unlock

Dim Rng As Range, CCtrl As ContentControl
 For Each Rng In ActiveDocument.StoryRanges
   For Each CCtrl In Rng.ContentControls
     CCtrl.Delete
   Next
 Next

End Sub

Sub ccs_Unlock()
Dim oStory As Range
Dim oCC As ContentControl
    For Each oStory In ActiveDocument.StoryRanges
        For Each oCC In oStory.ContentControls
            oCC.LockContentControl = False
        Next oCC
        If oStory.StoryType <> wdMainTextStory Then
            While Not (oStory.NextStoryRange Is Nothing)
                Set oStory = oStory.NextStoryRange
                For Each oCC In oStory.ContentControls
                    oCC.LockContentControl = False
                Next oCC
            Wend
        End If
    Next oStory
    
lbl_Exit:
    Set oStory = Nothing
    Set oCC = Nothing
    Exit Sub
End Sub

diana
3StarLounger
Posts: 279
Joined: 01 Jun 2010, 00:27

Re: Remove Word content controls & retain data

Post by diana »

Apologies for the late reply, Ive been away.

Thank you all, I'll take a look...