Spell Checking on a protected sheet

M

mooresk257

Hi,

I am using the following code for a spell cehcking control on a protected
sheet. I want to allow unlocked rows that have word wrap enabled to autofit
the contents of the unlocked rows.

Private Sub SpellCheck_Click()

ActiveSheet.Unprotect Password:="00000"
Cells.CheckSpelling _
CustomDictionary:="CUSTOM.DIC", _
IgnoreUppercase:=False, _
AlwaysSuggest:=True
ActiveSheet.Protect Password:="00000"
' Allow rows to be formatted (autofit) on a protected worksheet.
If ActiveSheet.Protection.AllowFormattingRows = False Then
ActiveSheet.Protect AllowFormattingRows:=True
End If

End Sub

This works except when this code runs and there is no spelling errors. Then,
it reprotects the sheet, but removes the password.

Any suggestions on how to fix this?

Thanks!
 
P

Patrick Molloy

does changing the protection line make a difference?

Private Sub SpellCheck_Click()

ActiveSheet.Unprotect Password:="00000"
Cells.CheckSpelling _
CustomDictionary:="CUSTOM.DIC", _
IgnoreUppercase:=False, _
AlwaysSuggest:=True
' Allow rows to be formatted (autofit) on a protected worksheet.
If ActiveSheet.Protection.AllowFormattingRows = False Then
ActiveSheet.Protect AllowFormattingRows:=True
End If

ActiveSheet.Protect Password:="00000" ' <=== moved to here

End Sub
 
M

mooresk257

I've tried that. It mostly solvevs the issue of removing the password, but
then the row formatting doesn't work, i.e. AllowFormattingRows = False.

I need to be able to have the rows autofit to wrapped text, which won't
happen unless the row formatting is allowed. Otherwsie I'd take that part of
the code out.
 

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