• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1992
  • Last Modified:

Activate Word macro when clicking checkbox

I have only written macros for Excel in the past, but am trying to get something that should be very simple to work in Word using a macro, and it is really turning out to be a pain. A co-worker has designed a form in Word that has multiple checkboxes and wants to enable them to be selected or deselected with a single click. I wrote the macro below and it works when I use the 'Run' command from the macro design dialogue box, however I can't figure out what code to use to cause the macro to run by clicking on the checkbox. I have tried various settings in the checkbox properties window and have the macro set to run on entry in the properties. I also haven't been able to find any specifics on the Internet to clarify the solution. What am I missing here? Thanks!
Sub OneClickCheckbox()
'
' OneClickCheckbox Macro
'
Dim blnClickValue As Boolean
blnClickValue = ActiveDocument.FormFields("Check1").CheckBox.Value
If blnClickValue = False Then
    ActiveDocument.FormFields("Check1").CheckBox.Value = True
Else
    ActiveDocument.FormFields("Check1").CheckBox.Value = False
End If
 
End Sub

Open in new window

0
TeleVidTech01
Asked:
TeleVidTech01
  • 2
1 Solution
 
GrahamSkanCommented:
There isn't an event exposed when a Form Field is clicked on a Word document, but you can designate any macro to be the one that is called when the field is selected (Entry) or unselected (Exit). The latter is more normally used.

You do this from the Properties... item in the context popup that appears when you right-click on the field (in unprotected mode)
0
 
TeleVidTech01Author Commented:
Well...that's what I'm having trouble with. I've tried selecting both entry and exit as options, but the macro doesn't fire when I mouse over, left-click, right-click, or double-click. But it works perfectly using the 'Run' command from the macros window. That's what has me puzzled.
0
 
GrahamSkanCommented:
An Entry macro should run when the selection changes to the field and the Exit macro runs when the selection changes from the field to another field.

You can do this by left-clicking on the field field that you are changing the selection to, or by tabbing between fields. The document must be in Protection mode for Form fields to work properly.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now