Problem with protected-form checkbox on single row of table

D

Dylan

I have a protected table of two rows with one row headings, the next row
contains a checkbox to allow the user to strikeout text in the adjacent cell.
The problem is that the cell containing the checkbox doesn't lose its focus
to enable the event to be initiated.

Since the document is protected and only one cell is active on this table,
whenever I select one of the other cells in the table, the focus returns to
the cell containing the checkbox.

The code I'm using, courtesy of Jean-Guy Marcil:

ToggleStrikeThru Selection.Range
ActiveDocument.Tables(1).Rows.Last.Select
End Sub
Sub ToggleStrikeThru(rngStrike As Range)

On Error Resume Next
Application.ScreenUpdating = False

If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If

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


'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If

Application.ScreenUpdating = True

End Sub
 
J

Jay Freedman

Hi Dylan,

There's nothing wrong with the code. It's just the nature of protected forms
and exit macros: The selection can't go anywhere, and the exit macro won't
fire, if there is no other form field for the cursor to go to.

The solution (which I've just verified) is to insert another form field -- a
check box or a text field will do -- in the same cell next to the first one,
and format it as Hidden text. The cursor can still jump to it, even though
it's hidden, and that will trigger the macro.

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

Dylan

Thanks Jay, it works a treat.

I added ActiveDocument.FormFields("Hidden01").Select to my code to make it
select the hidden formfield before ending the macro.

I may go back and include this to all checkbox fields.

Regards
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