Is there any method or macro to remove all content controls in MS Word?

允我心安 提交于 2020-07-10 00:59:48

问题


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:

  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:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!