0
在Excel單元格中的文本對齊我知道下面的Word VBA 2007碼檢查使用Word VBA 2007
objExcel.ActiveWorkbook.Sheets("Book1").Cells(3, 4)
可以得到一個打開的D3單元格(第3行,第4列)中的文本Excel
工作簿
工作表名爲「Book1」。但是如何獲得細胞的排列方式(即左,右,中心或正確)?謝謝!
在Excel單元格中的文本對齊我知道下面的Word VBA 2007碼檢查使用Word VBA 2007
objExcel.ActiveWorkbook.Sheets("Book1").Cells(3, 4)
可以得到一個打開的D3單元格(第3行,第4列)中的文本Excel
工作簿
工作表名爲「Book1」。但是如何獲得細胞的排列方式(即左,右,中心或正確)?謝謝!
控制水平單元對齊有兩個方面。首先是手動或通過代碼應用的強制非默認單元格對齊方式。第二種是xlGeneral
格式,根據數據的性質可以是右對齊,左對齊或中心對齊。
With objExcel.ActiveWorkbook.Sheets("Book1")
Select Case .Cells(3, 4).HorizontalAlignment
Case xlRight ' equal to -4152
Debug.Print "The cell is right-aligned."
Case xlCenter ' equal to -4108
Debug.Print "The cell is center-aligned."
Case xlLeft ' equal to -4131
Debug.Print "The cell is left-aligned."
Case xlGeneral ' equal to 1
Select Case Application.Evaluate("TYPE(" & .Cells(3, 4).Address(0, 0, external:=True) & ")")
Case 1
Debug.Print "The cell is right-aligned."
Case 2
Debug.Print "The cell is left-aligned."
Case 4, 16
Debug.Print "The cell is center-aligned."
Case Else
Debug.Print "The cell is part of an array."
End Select
End Select
End With
你確定這是你的工作,而不是你的工作簿被稱爲第一冊?
非常感謝!我在問題中更正了「工作簿」一詞。 – GreenPenguin