change color of checkbox with click event?

  • Thread starter got questions via OfficeKB.com
  • Start date

G

got questions via OfficeKB.com

Am creating a Word form with protected fields in Word 2003.

When critical checkbox's are clicked, I would like the box w/check to become
bold and change to red in order to stand out from the black of the other text.
Is there a way to do this?

Also - could this be countered, say, with a shift or ctrl click to change
back to black and clear the check?

Regards...
 
Ad

Advertisements

D

Doug Robbins - Word MVP

You can't do the bold, but the following will toggle the color of the
CheckBox to which the bookmark name of "Check2" is assigned if a macro
containing this code is run on exit from that checkbox

With ActiveDocument
.Unprotect
With .FormFields("Check2")
If .CheckBox.Value = True Then
.Range.Font.Color = wdColorRed
Else
.Range.Font.Color = wdColorAutomatic
End If
End With
.Protect wdAllowOnlyFormFields, NoReset
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

got questions via OfficeKB.com

Doug: my thanks for your reply, though I do have another question. I notice
you use unprotect/protect to run the code. What predicates whether the
document has to be 'unprotected' to run code? Just about all of the code I
have runs either with protection on or in an unprotected section.
 
J

Jay Freedman

Try running Doug's code without the Unprotect. The result will be a run-time
error 4605, "This method or property is not available because the object
refers to a protected area of the document".

In a protected document, any attempt to change anything about a formfield
other than its .Result (or, for a checkbox formfield, its .Checkbox.Value)
will get that error, as will any attempt to change text that isn't inside a
formfield.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
Ad

Advertisements

R

rm3

Doug Robbins - Word MVP wrote on 05/08/2008 20:10 ET
You can't do the bold, but the following will toggle the color of th
CheckBox to which the bookmark name of "Check2" is assigned if
macr
containing this code is run on exit from that checkbo

With ActiveDocumen
.Unprotec
With .FormFields("Check2"
If .CheckBox.Value = True The
.Range.Font.Color = wdColorRe
Els
.Range.Font.Color = wdColorAutomati
End I
End Wit
.Protect wdAllowOnlyFormFields, NoRese
End Wit

Hope this helps

Please reply to the newsgroup unless you wish to avail yourself of m
services on a paid consulting basis

Doug Robbins - Word MV

"got questions via OfficeKB.com" wrote in messag
news
Hi

This is very useful

However, can you please tell me how to apply it to all the check boxes in m
report from check1 to check158

Thank you so much!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top