N
nanook
I'm using Excel 2003 and am creating a template for others to use. However,
in order to restrict users from changing too much I have protected the sheet
and only unlocked some cells.
I then had a problem with the autofit not working where cells were merged
(and text wrapped) and the sheet password protected, so used this code
(Thanks Greg Wilson):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewRwHt As Single
Dim cWdth As Single, MrgeWdth As Single
Dim c As Range, cc As Range
Dim ma As Range
Dim ProtectStatus As Boolean
With Target
If .MergeCells And .WrapText Then
ProtectStatus = Me.ProtectContents
If ProtectStatus Then Me.Unprotect ' "password"
Set c = Target.Cells(1, 1)
cWdth = c.ColumnWidth
Set ma = c.MergeArea
For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next
Application.ScreenUpdating = False
On Error Resume Next
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = NewRwHt
cWdth = 0: MrgeWdth = 0
On Error GoTo 0
Application.ScreenUpdating = True
If ProtectStatus Then Me.Protect ' "password"
End If
End With
End Sub
However, I've now come across an issue - if someone writes text in a cell
(which is long enough to wrap and the height to be adjusted) and then clicks
either tab or enter to move to another cell, a pop-up appears asking for a
password in order to unprotect sheet. If the user then presses escape,
without entering a password, and then tools-protection-unprotect sheet it
doesn't ask for the password and just
unprotects!!
This means the document is not securely protected - what have I done wrong?
Thanks
in order to restrict users from changing too much I have protected the sheet
and only unlocked some cells.
I then had a problem with the autofit not working where cells were merged
(and text wrapped) and the sheet password protected, so used this code
(Thanks Greg Wilson):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewRwHt As Single
Dim cWdth As Single, MrgeWdth As Single
Dim c As Range, cc As Range
Dim ma As Range
Dim ProtectStatus As Boolean
With Target
If .MergeCells And .WrapText Then
ProtectStatus = Me.ProtectContents
If ProtectStatus Then Me.Unprotect ' "password"
Set c = Target.Cells(1, 1)
cWdth = c.ColumnWidth
Set ma = c.MergeArea
For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next
Application.ScreenUpdating = False
On Error Resume Next
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = NewRwHt
cWdth = 0: MrgeWdth = 0
On Error GoTo 0
Application.ScreenUpdating = True
If ProtectStatus Then Me.Protect ' "password"
End If
End With
End Sub
However, I've now come across an issue - if someone writes text in a cell
(which is long enough to wrap and the height to be adjusted) and then clicks
either tab or enter to move to another cell, a pop-up appears asking for a
password in order to unprotect sheet. If the user then presses escape,
without entering a password, and then tools-protection-unprotect sheet it
doesn't ask for the password and just
unprotects!!
This means the document is not securely protected - what have I done wrong?
Thanks