Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-09-2016, 05:37 AM
cryder cryder is offline Macro to run when a checkbox is selected Windows 8 Macro to run when a checkbox is selected Office 2010 64bit
Novice
Macro to run when a checkbox is selected
 
Join Date: Jan 2016
Posts: 6
cryder is on a distinguished road
Default Macro to run when a checkbox is selected

Hello. I have created a word document (2010) using content control boxes. Users have a an option to check a box besides each of the following:
Resolution


Information
Direction

What I would like to happen is if a user checks the box Resolution the next line would begin with the word "THAT" and they type the resolution.

If the user checks the box for either Information or Direction, the next line would start with the word "Staff" and then they can keep typing.

So for example, if a user select Resolution, on the next line the text would be something like this: THAT authority is given to proceed with the purchase.

If they select Information or Resolution, the next line would begin with
Staff submit this report as information.....

Is this possible? I am not an expert and am learning as I go. I am thinking a macro might work.

Thank you.

Cathy
Reply With Quote
  #2  
Old 01-09-2016, 06:29 AM
gmaxey gmaxey is online now Macro to run when a checkbox is selected Windows 7 32bit Macro to run when a checkbox is selected Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Unfortunately CCs don't have a built-in change event. You can create custom change events however they can be intimidating and unwieldy:
http://gregmaxey.com/word_tip_pages/...om_events.html

About the best you can do is employ the built-in On_Exit event where the event occurs when the user checks then tabs or clicks to the next control.

What is the range identifier of your "next line?" Is it another titled content control?
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 01-09-2016, 06:35 AM
cryder cryder is offline Macro to run when a checkbox is selected Windows 8 Macro to run when a checkbox is selected Office 2010 64bit
Novice
Macro to run when a checkbox is selected
 
Join Date: Jan 2016
Posts: 6
cryder is on a distinguished road
Default

Hello. Thank you for replying. The next line is just the start of a paragraph. After the user selects one if the check boxes they will put their cursor a the beginning of a new blank line.


Cathy
Reply With Quote
  #4  
Old 01-09-2016, 05:17 PM
gmaxey gmaxey is online now Macro to run when a checkbox is selected Windows 7 32bit Macro to run when a checkbox is selected Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Put the following code in the ThisDocument module of your VB Project:

Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim oRng As Word.Range
  Set oRng = ContentControl.Range.Paragraphs(1).Next.Range
  Select Case ContentControl.Title
    Case "A" 'Change to match your titles
      If ContentControl.Checked Then
        oRng.Text = "XXXX "
        oRng.Collapse wdCollapseEnd
        oRng.Select
      End If
    Case "B" 'Change to match your titles
      If ContentControl.Checked Then
        oRng.Text = "YYYY "
        oRng.Collapse wdCollapseEnd
        oRng.Select
      End If
    Case "C" 'Change to match your titles
      If ContentControl.Checked Then
        oRng.Text = "ZZZZ "
        oRng.Collapse wdCollapseEnd
        oRng.Select
      End If
  End Select
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 01-10-2016, 07:39 AM
cryder cryder is offline Macro to run when a checkbox is selected Windows 8 Macro to run when a checkbox is selected Office 2010 64bit
Novice
Macro to run when a checkbox is selected
 
Join Date: Jan 2016
Posts: 6
cryder is on a distinguished road
Default

Thank you. As I am learning what will this code do and do I need to make changes to it.

Thank you.

Cathy
Reply With Quote
  #6  
Old 01-10-2016, 07:51 AM
gmaxey gmaxey is online now Macro to run when a checkbox is selected Windows 7 32bit Macro to run when a checkbox is selected Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

After you change it to suit your specific need, it will do what you asked for it to do with the understanding that it is not automatic based on simply checking the box. The user has to check the box and then exit that box.

If you read the code you will discover what changes you need to make to it.

To be honest, you have choose a rather poor design. Check boxes are not mutually exclusive so there is nothing to keep your users from checking all three.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 01-10-2016, 09:14 AM
cryder cryder is offline Macro to run when a checkbox is selected Windows 8 Macro to run when a checkbox is selected Office 2010 64bit
Novice
Macro to run when a checkbox is selected
 
Join Date: Jan 2016
Posts: 6
cryder is on a distinguished road
Default

Perfect thank you so much for your help Greg. This works. Just for reference in the future what would be the better option than using check boxes to achieve the same results?

Cathy
Reply With Quote
  #8  
Old 01-10-2016, 09:22 AM
gmaxey gmaxey is online now Macro to run when a checkbox is selected Windows 7 32bit Macro to run when a checkbox is selected Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

The easiest way to ensure that only one choice is selected is to use a dropdown list. So instead of 3 checkboxes, use a dropdown list with three choices.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #9  
Old 01-10-2016, 09:25 AM
cryder cryder is offline Macro to run when a checkbox is selected Windows 8 Macro to run when a checkbox is selected Office 2010 64bit
Novice
Macro to run when a checkbox is selected
 
Join Date: Jan 2016
Posts: 6
cryder is on a distinguished road
Default

That totally makes sense. Again, many thanks. Enjoy your day.

Cathy
Reply With Quote
  #10  
Old 01-10-2016, 09:29 AM
gmaxey gmaxey is online now Macro to run when a checkbox is selected Windows 7 32bit Macro to run when a checkbox is selected Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,428
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Perhaps more elegant (but much more complicated) is a custom change event.
See: http://gregmaxey.com/word_tip_pages/...n_buttons.html
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to run when a checkbox is selected Clicking the selected Content Control checkbox returns wrong control in vba event DougsGraphics Word VBA 2 06-24-2015 07:31 AM
Macro to run when a checkbox is selected Use a checkbox and a macro to paste text destdixon Word 1 01-14-2013 07:29 AM
Macro to run when a checkbox is selected Asking for Macro to Reset Checkbox Control Excel Programming 4 12-11-2012 07:24 AM
Macro to calculate a value of a checkbox. stephen_ Excel Programming 1 06-27-2012 04:57 PM
macro on checkbox macrohelp Word VBA 0 03-06-2009 03:33 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:22 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft