使用 VB for Excel,但对 VB for Word 来说是新的。如果某个复选框被标记为 true,我不确定如何扩展标题。这是我目前拥有的代码,我得到一个运行时错误,说集合的请求成员不存在,但我在控件的属性窗口中命名了 CheckBox。我正在使用 Microsoft Word 版本 1808(内部版本 10730.20262 即点即用)。
Sub Macro1()
If ActiveDocument.FormFields("Licensing_1").CheckBox.Value = True Then
Do Until Selection.Find.Found = False
If Selection.Text Like "Licensing Discovery Questions" Then
Selection.Find.Style = ActiveDocument.Styles("Heading 1")
Selection.Find.Execute
Else: Selection.Paragraphs(1).CollapsedState = True
Selection.Find.Style = ActiveDocument.Styles("Heading 1")
Selection.Find.Execute
End If
Loop
End If
End Sub