Word 2007 Checkbox change color when checked
Need a little help here. In Word, I have a table with a check box in the first column. What I want to happen is when I check the box have the whole row fill in with a certain color. Can someone provide me with some code for this?
While searching the forums I saw some on changing font colors. Below is the start of that code, but It wouldn't work.
Private Sub CheckBox81_Click()
If CheckBox81.Value = vbChecked Then ForeColor = vbBlue
End Sub
Thanks for any help you can provide.
Re: Word 2007 Checkbox change color when checked
For starters you need to use the Microsoft Forms 2.0 Checkbox (judging by your code it looks like you are), the regular checkbox does not have the option to change colors.
Your code is close, Try it like:
vb Code:
Private Sub CheckBox81_Click()
If CheckBox81.Value = vbChecked Then
CheckBox81.ForeColor = vbBlue
End If
End Sub
Re: Word 2007 Checkbox change color when checked
Correction:
You may want to change it to a different color if someone unchecks it, because with the above code when they check it it will turn blue and stay blue. So....
vb Code:
Private Sub CheckBox81_Click()
If CheckBox81.Value = vbChecked Then
CheckBox81.ForeColor = vbBlue
Else:
CheckBox81.ForeColor = vbRed
End If
End Sub
Replace vbRed with the color you want it to be when they uncheck it.
Re: Word 2007 Checkbox change color when checked
That's great I'll try it and let you know how it works
Re: Word 2007 Checkbox change color when checked
Works great. Thanks!!!
Next challenge. Is there a way to highlight the entire row say yellow when I check the box?
Thanks!
Re: Word 2007 Checkbox change color when checked
I'll have to look at it later, but here's the code to highlight the selected text.
Code:
Selection.Range.HighlightColorIndex = wdYellow
Re: Word 2007 Checkbox change color when checked
vb Code:
ThisDocument.Tables(1).Rows(rownum).Range.HighlightColorIndex = wdBlue
change rownum and table index to suit
Re: Word 2007 Checkbox change color when checked
thanks guys for the help!! A couple more questions. Below is the code now that I have:
Private Sub CheckBox81_Click()
If CheckBox81.Value = vbChecked Then
CheckBox81.ForeColor = vbBlack
Else:
CheckBox81.ForeColor = vbRed
ThisDocument.Tables(6).Rows(3).Range.HighlightColorIndex = wdYellow
End If
End Sub
The Checkbox 81 is in row 3 of table 6 however it won't highlight that row. It will highlight any other row though. So if I change the row to say 4 then when I check the box in row 3 row 4 highlights. Any ideas?
Re: Word 2007 Checkbox change color when checked
Ok so this document is evolving as I think more and more.
What would be nice, but not sure if it's possible is when I check one of the boxes have it bring up a table of existing info requesting additional information to the item checked? Make sense?
I have a 13 page doc already with a table with many check boxes at the beginning of each row. Some of these will require inputs, but I don't want to clutter the doc up with all these tables if folks don't need certain rows checked.
Let me know what you guys think.
Thanks for the help!!
Re: Word 2007 Checkbox change color when checked
Word is much harder to work with for handeling data, its harder to look up information, and its harder to get it to do what you want. Access and Excel break the data up and allow you to look up/reference it many ways, while keeping a clean user interface.
If you are wanting a cleaner interface, and have more capabilities, you should look at moving your project to an Excel workbook, or even better, Access. This will allow you to reference/lookup information much easier, and the data can come from hidden sheets/tables that the user will never see if you don't want them to.
Re: Word 2007 Checkbox change color when checked
Quote:
The Checkbox 81 is in row 3 of table 6 however it won't highlight that row.
i tested this in a single table, without issue
Quote:
What would be nice, but not sure if it's possible is when I check one of the boxes have it bring up a table of existing info requesting additional information to the item checked?
you can completely hide the table and only show again when the checkbox is checked
vb Code:
Private Sub CheckBox3_Click()
If CheckBox3.Value Then
ThisDocument.Tables(1).Range.Font.Hidden = False
ThisDocument.Tables(1).Rows.Height = 16
CheckBox3.Caption = "Hide Table"
Else
ThisDocument.Tables(1).Range.Font.Hidden = True
ThisDocument.Tables(1).Rows.Height = 0
CheckBox3.Caption = "Show Table"
End If
End Sub
you could also use a toggle button instead of check box
if the checkbox is within the table then that row needs to be sized to hold /show the checkbox, while the rest of the rows do not show
Re: Word 2007 Checkbox change color when checked
Hi, I'm completely new with programming in MS Word, I know this is an old thread, but can someone explain how I use this code with the visual basic feature in word to get color changing check boxes? Also how do I use the Microsoft Forms 2.0 checkbox?
Re: Word 2007 Checkbox change color when checked
forms 2.0 controls are the controls added to userforms or documents (activex controls) in word or excel
add a checkbox and try the code above, make sure the name of the check box matches the code
Re: Word 2007 Checkbox change color when checked
Quote:
Originally Posted by
westconn1
forms 2.0 controls are the controls added to userforms or documents (activex controls) in word or excel
add a checkbox and try the code above, make sure the name of the check box matches the code
So I added the code (in the right spot?) When I save it I don't see any difference.. http://screencast.com/t/794pexZ7bhL
The checkbox I used was in the developer tab: http://screencast.com/t/5ufdnuK9.. how do I know what the name is?
Sorry for my ignorance.. trying to learn.
Re: Word 2007 Checkbox change color when checked
Quote:
how do I know what the name is?
right click on it and properties
Quote:
So I added the code (in the right spot?)
to put in the right spot, use the drop down boxes at the top of the code pane, if the event is not there, you are in the wrong code pane
Re: Word 2007 Checkbox change color when checked
So right clicking on the checkbox doesn't show a properties to find the name: http://screencast.com/t/wus5T3dR5JNE Obviously I'm not looking in the right place, I also see the dropboxes in the code pane but what event am I looking for?
Is there a lesson on how to work in word's VB for complete novices?
Re: Word 2007 Checkbox change color when checked
Quote:
Originally Posted by
westconn1
right click on it and properties
So I changed the tag name in the properties of a test checkbox to 'myCheckbox' http://screencast.com/t/6fzOPc7Mwi3e
when I changed the name in the document code section for the above code I got this message when i tried to run it: http://screencast.com/t/5umqY8G5W
any other ideas?
Re: Word 2007 Checkbox change color when checked
the tag property is not the name property
if you want people to look at your images, put them in your post, not some external link
Quote:
I also see the dropboxes in the code pane but what event am I looking for?
in the left side one look for the mycheckbox and select, once selected the right side one will have the options for mycheckbox
if mycheckbox is not in the left side one see if there is any checkbox, as that is probably the correct name for your checkbox, or if no checkbox there the control added is not the correct type of control, that is it could be a form checkbox (which has no events), as different to an activex (forms2) checkbox
Quote:
Is there a lesson on how to work in word's VB for complete novices?
google can help