Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k views
in Technique[技术] by (71.8m points)

Using wdContentControlCheckBox in Word 2016

I recorded a Word macro which inserts a checkbox. The checkbox gets inserted, but the text does not. Why? fwiw I'm using Word 2016 on Windows 10.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Macros from the Recorder are just a starting point. Here is your recording turned into a functioning macro:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...