PDA

View Full Version : Recording Macro with a Checkbox?



AGI_MEG
10-24-2014, 02:51 PM
I'm using a Word template that the user will complete and then save to create the document. I want to have checkboxes in the document that the user can turn on/off as needed for each version they are going to save.

I'm reading an external file and based on its data contents the checkboxes will be initially set on and off accordingly.

My issue is with the CHECKBOXES in the DEVELOPER ribbon. I typically "write code" by recording a macro. However, when I start a macro recording, it will not let me "check" the CHECKBOX. If I pause the macro, then I can check it on and off.

I've tried to research this issue and have seen something about LEGACY toolkit. What are these?

I'm sure it is something simple but I can't seem to conquer it.

Any assistance would be appreciated.

AGI_MEG

gmayor
10-24-2014, 09:55 PM
It is a fact of life that the macro recorder will not record all commands, and it doesn't often use the most efficient code. If you want to insert a check box using VBA you will have to do it manually. You didn't say what kind of check box, but assuming that you want to insert a legacy form field check box at the cursor position the code would be


Dim oFld As FormField
Set oFld = ActiveDocument.FormFields.Add(Selection.Range, wdFieldFormCheckBox)
oFld.CheckBox.Value = True 'or False

I don't know which Legacy toolkit you are referring to, but it may be Greg Maxey's useful ribbon addition http://gregmaxey.mvps.org/word_tip_pages/add_classic_form_controls.html. However this will not affect the issue regarding the macro recorder.