|
-
Apr 27th, 2011, 10:14 AM
#1
Thread Starter
New Member
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.
-
Apr 27th, 2011, 07:13 PM
#2
Hyperactive Member
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
-
Apr 27th, 2011, 07:30 PM
#3
Hyperactive Member
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.
-
May 2nd, 2011, 07:57 AM
#4
Thread Starter
New Member
Re: Word 2007 Checkbox change color when checked
That's great I'll try it and let you know how it works
-
May 2nd, 2011, 08:22 AM
#5
Thread Starter
New Member
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!
-
May 2nd, 2011, 04:43 PM
#6
Hyperactive Member
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
-
May 3rd, 2011, 09:20 PM
#7
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 4th, 2011, 01:18 PM
#8
Thread Starter
New Member
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?
-
May 4th, 2011, 02:09 PM
#9
Thread Starter
New Member
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!!
-
May 4th, 2011, 02:54 PM
#10
Hyperactive Member
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.
-
May 4th, 2011, 11:58 PM
#11
Re: Word 2007 Checkbox change color when checked
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
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 23rd, 2016, 03:07 PM
#12
New Member
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?
-
Feb 23rd, 2016, 03:24 PM
#13
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 23rd, 2016, 03:29 PM
#14
New Member
Re: Word 2007 Checkbox change color when checked
 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.
-
Feb 23rd, 2016, 03:39 PM
#15
Re: Word 2007 Checkbox change color when checked
how do I know what the name is?
right click on it and properties
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
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 23rd, 2016, 03:48 PM
#16
New Member
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?
-
Feb 23rd, 2016, 04:42 PM
#17
New Member
Re: Word 2007 Checkbox change color when checked
 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?
-
Feb 24th, 2016, 02:52 AM
#18
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
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
Is there a lesson on how to work in word's VB for complete novices?
google can help
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|