当前位置: 代码迷 >> VBA >> Excel_VBA 设立单元格的对齐方式
  详细解决方案

Excel_VBA 设立单元格的对齐方式

热度:6009   发布时间:2013-02-26 00:00:00.0
Excel_VBA 设置单元格的对齐方式
Public Sub 技巧4_151()
    Dim myRange As Range
    Set myRange = Range("A1")             '指定任意单元格
    With myRange
        .Value = "ExcelVBA实用技巧大全"
        .HorizontalAlignment = xlRight
        MsgBox "水平右对齐。"
        .HorizontalAlignment = xlLeft
        MsgBox "水平左对齐。"
        .HorizontalAlignment = xlCenter
        MsgBox "水平居中。"
        .HorizontalAlignment = xlDistributed
        MsgBox "水平分散对齐。"
        .VerticalAlignment = xlTop
        MsgBox "垂直靠上。"
        .VerticalAlignment = xlBottom
        MsgBox "垂直靠下。"
        .VerticalAlignment = xlCenter
        MsgBox "垂直居中。"
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlGeneral
        MsgBox "恢复默认。"
    End With
    Set myRange = Nothing
End Sub