问题
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
回答1:
I was able to remove all content controls (in Word 2013) without any macros as follows:
- On the developer menu, select Design Mode.
- If no content controls are visible, scroll through until one is.
- Press Ctrl+A to select the entire document.
- Right-click a visible content control.
- In the context menu, click Remove Content Control.
I don't know if it works for all types of Content Controls.
回答2:
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.
回答3:
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
来源:https://stackoverflow.com/questions/36162589/is-there-any-method-or-macro-to-remove-all-content-controls-in-ms-word