在 Word 2016 中使用 wdContentControlCheckBox

Using wdContentControlCheckBox in Word 2016

我录制了一个插入复选框的 Word 宏。复选框被插入,但文本没有。为什么? 首先我在 Windows 10.

上使用 Word 2016
    Sub CheckBox()
'
' CheckBox Macro
'
'
    Selection.Range.ContentControls.Add (wdContentControlCheckBox)
    Selection.MoveRight Unit:=wdCharacter, Count:=2
    Selection.TypeText Text:=" z"
End Sub

这样试试:

Sub CheckBox()
With Selection.Range
  .Text = " z"
  .Collapse wdCollapseStart
  .ContentControls.Add wdContentControlCheckBox
End With
End Sub

记录器中的宏只是一个起点。这是你的录音变成了一个有效的宏:

Sub Checkbox()
  With Selection
    .Range.ContentControls.Add (wdContentControlCheckBox)
    .MoveRight Unit:=wdCharacter, Count:=2
    .Range.Text = " z"
  End With
End Sub