请参考以下示例。在记录集中,可以设置该记录集的Range对象,对全部字段(即各列)设置EntireColumn.AutoFit,可实现按该字段的最合适列宽。
With ActiveSheet
Cells.Select
With Selection
.VerticalAlignment = xlCenter '设置整张表行居中
End With
.Cells(2, 5).RowHeight = 22 '设置Row=2,col=5,行高=22
.Cells(2, 5).EntireRow.AutoFit '最合适的行高
.Cells(2, 5).ColumnWidth = 50 '该单元所在列宽=50
.Cells(2, 5).EntireColumn.AutoFit '最合适的列宽
End With
With ActiveSheet
Cells.Select
With Selection
.VerticalAlignment = xlCenter '设置整张表行居中
End With
.Cells(2, 5).RowHeight = 22 '设置Row=2,col=5,行高=22
.Cells(2, 5).EntireRow.AutoFit '最合适的行高
.Cells(2, 5).ColumnWidth = 50 '该单元所在列宽=50
.Cells(2, 5).EntireColumn.AutoFit '最合适的列宽
End With
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货