「EXCEL VBA 儲存格的格式設定」:修訂間差異
跳至導覽
跳至搜尋
| 第41行: | 第41行: | ||
Rows("1:1").EntireRow.AutoFit | Rows("1:1").EntireRow.AutoFit | ||
===================================== | ===================================== | ||
'儲存格的資料格式: | '儲存格的資料格式: | ||
Selection.NumberFormatLocal = "G/通用格式" | Selection.NumberFormatLocal = "G/通用格式" | ||
Selection.NumberFormatLocal = "0.00_ " | Selection.NumberFormatLocal = "0.00_ " | ||
Selection.NumberFormatLocal = "$#,##0.00" | Selection.NumberFormatLocal = "$#,##0.00" | ||
Selection.NumberFormatLocal = | Selection.NumberFormatLocal = "_-$* #,##0.00_-;-$* #,##0.00_-;_-$* ""-""??_-;_-@_-" | ||
"_-$* #,##0.00_-;-$* #,##0.00_-;_-$* ""-""??_-;_-@_-" | Selection.NumberFormatLocal = "yyyy/m/d" | ||
Selection.NumberFormatLocal = "yyyy/m/d" | Selection.NumberFormatLocal = "[$-F400]h:mm:ss AM/PM" | ||
Selection.NumberFormatLocal = "[$-F400]h:mm:ss AM/PM" | Selection.NumberFormatLocal = "0.00%" | ||
Selection.NumberFormatLocal = "0.00%" | Selection.NumberFormatLocal = "# ?/?" | ||
Selection.NumberFormatLocal = "# ?/?" | Selection.NumberFormatLocal = "0.00E+00" | ||
Selection.NumberFormatLocal = "0.00E+00" | Selection.NumberFormatLocal = "@" | ||
Selection.NumberFormatLocal = "@" | Selection.NumberFormatLocal = "000" | ||
Selection.NumberFormatLocal = "000" | |||
===================================== | ===================================== | ||
Selection.Font.Name = "新細明體" | Selection.Font.Name = "新細明體" | ||
Range("A1").Font.Name = "標楷體" | Range("A1").Font.Name = "標楷體" | ||
MsgBox Range("A1").Font.Name | MsgBox Range("A1").Font.Name | ||
Selection.Font.ColorIndex = '設定字體的顏色 | Selection.Font.ColorIndex = '設定字體的顏色 | ||
Selection.Font.Size = '設定字體的大小 | Selection.Font.Size = '設定字體的大小 | ||
===================================== | ===================================== | ||
Range("A1").Select | Range("A1").Select | ||
With Selection.Font | With Selection.Font | ||
.Name = "新細明體" | .Name = "新細明體" | ||
.Size = "20" | .Size = "20" | ||
.Bold = True | .Bold = True | ||
.Italic = True | .Italic = True | ||
.Underline = True | .Underline = True | ||
End With | End With | ||
======================================= | ======================================= | ||
於 2015年8月12日 (三) 19:47 的最新修訂
EXCEL VBA:儲存格的格式設定
======
Range("A1").Select With Selection
.HorizontalAlignment = xlLeft '水平對齊
.VerticalAlignment = xlCenter '鉛直對齊
.WrapText = False '設定自動換列
.Orientation = 0 '設定方向的角度
.AddIndent = False '設定縮排
.IndentLevel = 0 '設定縮排的值
.ShrinkToFit = False '設定縮小字形以適合欄寬
'設定文字方向,xlContext內容,xlLTR從左至右,xlRTL從右至左
.ReadingOrder = xlContext '設定文字方向
.MergeCells = False '設定合拼儲存格
.Interior.ColorIndex = 9 '填滿的顏色
End With
======
水平對齊: .HorizontalAlignment 的設定值:
xlGeneral 通用格式 xlLeft 靠左 xlCenter中間對齊 xlRight靠右 xlFill 填滿 xlJustify 段落重排 xlCenterAcrossSelection 跨欄置中 xlDistributed 分散對齊 ( 縮排 )
鉛直對齊: .VerticalAlignment的設定值:
xlTop 靠上 xlCenter 置中對齊 xlBottom 靠下 xlJustify段落重排 xlDistributed分散對齊
=====================================
'自動調整行高列寬 Columns("A:A").EntireColumn.AutoFit Rows("1:1").EntireRow.AutoFit
===================================== '儲存格的資料格式: Selection.NumberFormatLocal = "G/通用格式" Selection.NumberFormatLocal = "0.00_ " Selection.NumberFormatLocal = "$#,##0.00" Selection.NumberFormatLocal = "_-$* #,##0.00_-;-$* #,##0.00_-;_-$* ""-""??_-;_-@_-" Selection.NumberFormatLocal = "yyyy/m/d" Selection.NumberFormatLocal = "[$-F400]h:mm:ss AM/PM" Selection.NumberFormatLocal = "0.00%" Selection.NumberFormatLocal = "# ?/?" Selection.NumberFormatLocal = "0.00E+00" Selection.NumberFormatLocal = "@" Selection.NumberFormatLocal = "000"
=====================================
Selection.Font.Name = "新細明體"
Range("A1").Font.Name = "標楷體"
MsgBox Range("A1").Font.Name
Selection.Font.ColorIndex = '設定字體的顏色
Selection.Font.Size = '設定字體的大小
=====================================
Range("A1").Select
With Selection.Font
.Name = "新細明體"
.Size = "20"
.Bold = True
.Italic = True
.Underline = True
End With