vba - Word 2016-如何在 VBA 中添加/删除重复部分内容控件
解决方案
这个宏将插入一个重复的部分 CC:
Sub AddRepeatingSectionCC()
Dim oCC As ContentControl
Set oCC = ActiveDocument.ContentControls.Add(wdContentControlRepeatingSection, Selection.Range)
With oCC
.AllowInsertDeleteSection = True
.RepeatingSectionItemTitle = "Repeating Section Item"
End With
Set oCC = Nothing
End Sub
这是用于设置其他 CC 选项的第二个宏:
Sub SetOptions()
If Selection.Information(wdInContentControl) Then
With Selection.ParentContentControl
'Sets the appearance to the original bounding box look. For the newer tags look, use wdContentControlTags
'If you don't need to change a setting, comment it out before running the macro
.Appearance = wdContentControlBoundingBox
'Sets the color of the control to a preset color
.Color = wdColorWhite
'Sets whether the Content Control can be deleted or not. If the control has had .Temporary = True applied, you must reverse that property to True before applying this.
.LockContentControl = True
'Sets whether the contents of the Content Control can be deleted or not.
.LockContents = False
'Sets the placeholder text or prompt for the control
.SetPlaceholderText , , "Default Text"
'Sets the Content Control tag property
.Tag = "Tag"
'If this is set to true, the Content Control will be removed when the contents are edited.
.Temporary = False
'Sets the title of the Content Control. This appears on a tab above the control when it is activated.
.Title = "Title"
End With
Else
MsgBox "Please select a Content Control to change its options."
End If
End Sub
要删除它:
Sub DeleteCC()
If Selection.Information(wdInContentControl) Then
Selection.ParentContentControl.Delete
Else
MsgBox "Please select a Content Control to delete it."
End If
End Sub
推荐阅读
- javascript - 在 Nodejs Express App Route 中不起作用
- expect - 如何使用 expect 绕过最初的 `Press return to continue.` 齐声的问题?
- postgresql - postgres 无法访问 777 文件
- c++ - 如何从 C++ 中的未命名派生类调用非默认父构造函数?
- java - Spring Cloud Kinesis Binder 如何为生产者处理错误 - 根据文档,它不起作用
- android-intent - 如何在没有 intent.addFlags 的情况下将意图从适配器传递给 Activity?
- angular - 如何在计时器中继续 catchError (rxjs)
- python-3.x - VS 代码中的 EOF 错误(也不能在终端中工作)
- python - 尝试在序列化程序“QuestionSerializer”上获取字段“choice_option_set”的值时出现 AttributeError
- javascript - 如何在没有任何提交按钮的情况下提交模板驱动的角度表单?