我有一本工作簿,里面有几张我想保护的工作表。我没有在保护上使用密码。我有一些与此表相关联的可视化基本代码,以扩展合并单元格的行宽。当工作表受到保护时,代码将不起作用。
我确实找到了一些关于在我的代码中添加不受保护的代码的指导,但无法弄清楚将它放在哪里以及如何解决没有密码的事实。进一步的指导将不胜感激!
这是我的代码:
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
With Target
If .MergeCells And .WrapText Then
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
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
Application.ScreenUpdating = True
End If
End With
End Sub