protected form checkbox macro


D

DDawson

This was previously discussed as subject "RE: if chkbox is ticked then
un-strikethrough textbox text" - where I used an active-x control as the
checkbox, but I found out that I need to use a protected form. I want to
convert Jean-Guy Marcil's code (thank you Jean!) to something I can use with
a protected checkbox.

So far I have...

Sub Click() 'I call this in the checkbox properties - run macro on
entry/exit
ToggleStrikeThru Selection.Range
End Sub

I get a Runtime Error 5941 with the next part (The requested member of the
collection does not exist)

Sub ToggleStrikeThru(rngStrike As Range)

With rngStrike.Rows(1)
.Cells(2).Range.Font.DoubleStrikeThrough = Not _
.Cells(1).Range.InlineShapes(1).OLEFormat.Object.Value
.Cells(3).Range.Font.DoubleStrikeThrough = Not _
.Cells(1).Range.InlineShapes(1).OLEFormat.Object.Value
End With
End Sub
 
Ad

Advertisements

J

Jean-Guy Marcil

DDawson said:
This was previously discussed as subject "RE: if chkbox is ticked then
un-strikethrough textbox text" - where I used an active-x control as the
checkbox, but I found out that I need to use a protected form. I want to
convert Jean-Guy Marcil's code (thank you Jean!) to something I can use with
a protected checkbox.

So far I have...

Two things...
1) The code I previously posted was working with ActiveX controls, which are
different from form fields ("InlineShapes(1).OLEFormat" vs
"FormFields(1).CheckBoxes")
2) To work with text in a protected document, you have to first unprotect
it...

Try this:


Sub Click()

ToggleStrikeThru Selection.Range

End Sub


Sub ToggleStrikeThru(rngStrike As Range)

ActiveDocument.Unprotect

With rngStrike.Rows(1)
.Cells(2).Range.Font.DoubleStrikeThrough = Not _
.Cells(1).Range.FormFields(1).CheckBox.Value
.Cells(3).Range.Font.DoubleStrikeThrough = Not _
.Cells(1).Range.FormFields(1).CheckBox.Value
End With

ActiveDocument.Protect wdAllowOnlyFormFields, True

End Sub
 
D

dd

Hi Jean

I've tried this at home, using Word 2000 and I find when I click the
checkbox nothing happens, but then when I click another cell, after clicking
the textbox, it works.

I've added screen updating to the beginning and end, but no difference.
I've tried to add .Cells(2).Select, to the end of the With
rngStrike.Rows(1), but this doesn't work either.

Is there anything else you can do to make it update on clicking?

Dylan
 
J

Jean-Guy Marcil

dd said:
Hi Jean

I've tried this at home, using Word 2000 and I find when I click the
checkbox nothing happens, but then when I click another cell, after clicking
the textbox, it works.

I've added screen updating to the beginning and end, but no difference.
I've tried to add .Cells(2).Select, to the end of the With
rngStrike.Rows(1), but this doesn't work either.

Is there anything else you can do to make it update on clicking?

No!
Remember, the trigger is an "OnExit" event, not a "Click" event. You have to
leave the checkbox for the code to be triggered... either tab out, or click
elsewhere...
 
Ad

Advertisements

D

dd

Jean-Guy,

This is excellent and it does exactly what I want, but can you tell me how
to reverse it so that when the checkbox is checked - the text is
struckthrough.

Hope its not too much trouble, I really appreciate it.

Dylan
 

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