| ===以毫米为单位设置行高和列宽

下面的宏使您可以使用毫米作为比例来设置行高和列宽:

Sub SetColumnWidthMM(ColNo As Long, mmWidth As Integer)

' changes the column width to mmWidth

Dim w As Single

If ColNo < 1 Or ColNo > 255 Then Exit Sub

Application.ScreenUpdating = False

w = Application.CentimetersToPoints(mmWidth / 10)

While Columns(ColNo + 1).Left - Columns(ColNo).Left - 0.1 > w

Columns(ColNo).ColumnWidth = Columns(ColNo).ColumnWidth - 0.1

Wend

While Columns(ColNo + 1).Left - Columns(ColNo).Left + 0.1 < w

Columns(ColNo).ColumnWidth = Columns(ColNo).ColumnWidth + 0.1

Wend

End Sub

Sub SetRowHeightMM(RowNo As Long, mmHeight As Integer)

' changes the row height to mmHeight

If RowNo < 1 Or RowNo > 65536 Then Exit Sub

Rows(RowNo).RowHeight = Application.CentimetersToPoints(mmHeight / 10)

End Sub

此示例宏显示如何将第3行的行高和C列的列宽设置为3.5厘米:

Sub ChangeWidthAndHeight()

SetColumnWidthMM 3, 35

SetRowHeightMM 3, 35

End Sub