大众计算机学习网

专门提供各种电脑教程

VBA自行设置Excel工作表行高列宽以及恢复行高列宽为默认值

Admin | 2010-7-7 12:29:39 | 被阅次数 | 12719

  ①VBA自行设置行高

  Sub SetMyRowHeight()
   MsgBox "将当前单元格所在的行高设置为29"
   Dim rRow As Long, iRow As Long
   rRow = ActiveCell.Row
   iRow = ActiveSheet.Rows(rRow).RowHeight
   ActiveSheet.Rows(rRow).RowHeight = 29
   MsgBox "恢复到原来的行高"
   ActiveSheet.Rows(rRow).RowHeight = iRow
  End Sub

  ②VBA自行设置列宽

  Sub SetMyColumnWidth()
   MsgBox "将当前单元格所在列的列宽设置为36"
   Dim cColumn As Long, iColumn As Long
   cColumn = ActiveCell.Column
   iColumn = ActiveSheet.Columns(cColumn).ColumnWidth
   ActiveSheet.Columns(cColumn).ColumnWidth =36
   MsgBox "恢复至原来的列宽"
   ActiveSheet.Columns(cColumn).ColumnWidth = iColumn
  End Sub

  ③VBA恢复行高列宽为默认值

  Sub ReSetMyRowHeightAndColumnWidth()
   MsgBox "将当前单元格所在的行高和列宽恢复为标准值"
   Selection.UseStandardHeight = True
   Selection.UseStandardWidth = True
  End Sub