Excel中利用VBA设置列宽和行高

如果要用VBA来设置区域的行高和列宽,可以用Range.ColumnWidth 属性和Range.RowHeight 属性,例如下例将选定的区域中各单元格的列宽和行高调整为指定的数值:

Sub SetColumnAndRow()
With ActiveWindow.RangeSelection
.ColumnWidth = 3
.RowHeight = 19
End With
End Sub

如果要将选定区域内的各单元格的列宽和行高调整为最合适的值,可以用下面的代码:

Sub SetColumnAndRow()
With ActiveWindow.RangeSelection
.Columns.AutoFit
.Rows.AutoFit
End With
End Sub

下面的代码将活动工作表中的所有单元格的行高和列宽恢复为默认值:

Sub SetDefault()
With ActiveSheet
.Columns.ColumnWidth = .StandardWidth
.Rows.RowHeight = .StandardHeight
End With
End Sub

office办公软件入门基础教程 » Excel中利用VBA设置列宽和行高

本文链接:【Excel中利用VBA设置列宽和行高】https://www.officeapi.cn/34685.html

OFFICE,天天学一点,进步多一点

联系我们