VBA_對齊方式_HorizontalAlignment


在制作報表的時候,會遇到要調整單元格或者區域的對齊方式,用Range.HorizontalAlignment 屬性就可以

代碼片段

Sub HorizontalAlignment()
Dim r As Range
Set r = Range("A1:E1")

With r
'寫入文本到第一個單元格
.Cells(1, 1).Value = "HorizontalAlignment"
'設置對齊方式
.HorizontalAlignment = xlHAlignCenterAcrossSelection
End With

Set r = Nothing

End Sub

幾種對齊方式:

Specifies the horizontal alignment for the object.

  

名稱 說明
xlHAlignCenter -4108 居中。
xlHAlignCenterAcrossSelection 7 跨列居中。
xlhaligndistributedxlhalignfill -4117 分散對齊。
xlhaligngeneral 5 填充。
xlhalignjustify 1 按數據類型對齊。
xlhalignleft -4130 兩端對齊。
xlHAlignLeft -4131 靠左。
xlHAlignRight -4152 靠右。

https://docs.microsoft.com/zh-cn/office/vba/api/excel.xlhalign

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM