Activate Word macro when clicking checkbox

Posted on 2009-04-16
Last Modified: 2012-05-06
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


    ActiveDocument.FormFields("Check1").CheckBox.Value = False

End If

End Sub

Open in new window

Question by:TeleVidTech01
    LVL 76

    Expert Comment

    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)

    Author Comment

    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.
    LVL 76

    Accepted Solution

    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.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
    Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
    The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
    Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now