繁体   English   中英

是否有任何方法或宏可以删除MS Word中的所有内容控件?

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

我需要删除活动文档中的所有内容控制器(“已锁定”和“未锁定”),而不删除任何文本。 我已经搜索并为此找到了一个宏。 但我认为它无法正常工作。

Word VBA删除带有特定标签的内容控件

是否有可能做到这一点?

编辑:我已经尝试下面的代码。 它将删除带有文本内容的内容控制器。 我只需要删除内容控制器。

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

我能够删除没有任何宏的所有内容控件(在Word 2013中),如下所示:

  1. 在开发人员菜单上,选择“设计模式”。
  2. 如果看不到任何内容控件,请滚动浏览直到一个。
  3. 按Ctrl + A选择整个文档。
  4. 右键单击可见的内容控件。
  5. 在上下文菜单中,单击“删除内容控件”。

我不知道它是否适用于所有类型的内容控件。

我已经找到了答案:)

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

这将对某人有所帮助。

感谢您的回答-这正是我想要的。 我最终使用以下内容:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM