4

I need to remove all content controllers (Loked and unlocked) in active document without removing any text. I've search and found a macro for this. But I think it's not work properly.

Word VBA to delete Content Controls with specific Tags

Is it possible to do this?

Edited: I've tried below code. It'll remove content controllers with text content. I need to remove only content controllers.

Sub Test()
Dim objCC As ContentControl
Do While ActiveDocument.ContentControls.Count > 0
For Each objCC In ActiveDocument.ContentControls
objCC.Delete True
Next
Loop
End Sub
4
  • 2
    HOW is it not working properly? Mar 22, 2016 at 19:27
  • 1
    Loop over ActiveDocument.ContentControls and delete each item.
    – Florent B.
    Mar 22, 2016 at 19:34
  • @ Cindy Meister: It's not work properly means I didn't see any change in the document after running that macro code. I've try to remove the content controllers from this document. Download
    – Thilina
    Mar 23, 2016 at 13:56
  • @ Florent B: Thanks, Can you provide an answer with example code to me.
    – Thilina
    Mar 23, 2016 at 14:03

4 Answers 4

14

I was able to remove all content controls (in Word 2013) without any macros as follows:

  1. On the developer menu, select Design Mode.
  2. If no content controls are visible, scroll through until one is.
  3. Press Ctrl+A to select the entire document.
  4. Right-click a visible content control.
  5. In the context menu, click Remove Content Control.

I don't know if it works for all types of Content Controls.

2
  • 5
    Saving a document in the older .doc format will also remove any content controls, leaving behind only the displayed content.
    – macropod
    Mar 28, 2019 at 20:59
  • 1
    Thank you @macropod. I was going crazy trying to figure out why Word wasn't behaving.
    – Robert
    Jun 30, 2020 at 7:00
7

I've found the answer by my own way :)

Public Sub Test()

  Dim oRng As Range
  Dim CC   As ContentControl
  Dim LC   As Integer
  Dim LRCC As Integer
  Dim LTCC As Integer
  Dim LE   As Boolean

'Remove all content controls
Set oRng = ActiveDocument.Content
LTCC = LTCC + oRng.ContentControls.Count
For LC = oRng.ContentControls.Count To 1 Step -1

Set CC = oRng.ContentControls(LC)
If CC.LockContentControl = True Then
    CC.LockContentControl = False
End If
CC.Delete
If Not LE Then
    LRCC = LRCC + 1
    End If
    LE = False
Next
End Sub

This will helpful to someone.

0
2

Thanks for this answer--it was just what I was looking for. I ended up using the following:

Sub ContentControlRemoval()
'
'Remove all content controls
Set oRng = ActiveDocument.Content
LTCC = LTCC + oRng.ContentControls.Count
For LC = oRng.ContentControls.Count To 1 Step -1

Set CC = oRng.ContentControls(LC)
If CC.LockContentControl = True Then
    CC.LockContentControl = False
End If
CC.Delete
If Not LE Then
    LRCC = LRCC + 1
    End If
    LE = False
Next
End Sub
0

@macropod's answer still works with the newest version of Word and for nonprogrammers was way easier. I did a "Save As" in an older version Word in the dropdown, then restored with another "Save As" to my current Word. It did ask if I was aware I was saving to Open XML. I said Y.

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Aug 21 at 15:35

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.