为什么要禁止调整列宽和行高呢,难道有什么特别的作途吗?
这里采用一种迂回的办法,非常简单且易于理解。
在您想禁止调整列宽行高的工作表模块的事件代码中,输入下面的代码:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Long
Dim lRowCount As Long
Dim lColumnCount As Long
lRowCount = Cells.Rows.Count
lColumnCount = Cells.Columns.Count
Application.ScreenUpdating = False
For i = 1 To lColumnCount
If Columns(i).ColumnWidth <> 8.38 Then Columns(i).ColumnWidth = 8.38
Next
For i = 1 To lRowCount
If Rows(i).RowHeight <> 14.25 Then Rows(i).RowHeight = 14.25
Next
Application.ScreenUpdating = True
End Sub
这样,当用改变该工作表的列宽和行高后,再回到该工作表中时会自动恢复为原来的列宽行高。因为要遍历工作表中的所有行列,稍稍有点慢。