2015-08-13 80 views
1

在Excel VBA中,我試圖將一個參數值傳遞給屬性'VerticalAlignment'。我得到的錯誤是:「無法設置Range類的Horizo​​ntalAlignment屬性」。很明顯,問題出在'horzAlign'的'vertAlign'值,但是,什麼?Excel VBA - 將屬性值傳遞給屬性

' Merge the range & horizontal & vertical 
' alignment as per arguments 
Sub mergeCellsWithLeftAlign(ByVal curRange As Range, _ 
    ByVal horzAlign As String, ByVal vertAlign As String) 

     With curRange 
      .HorizontalAlignment = horzAlign 
      .VerticalAlignment = vertAlign 
      .MergeCells = True 
     End With 
End Sub 

這是被稱爲在另一個過程是這樣的:

Call mergeCellsWithLeftAlign(Range("F10:F11"), "xlLeft", "xlBottom") 
+0

什麼是已經回答了你的'horzAlign'和'vertAlign' – psychicebola

+1

@psychicebola保羅的可能值。它是一個整數常量。謝謝 – Kayote

+1

@psychicebola:不管:它們不應該是String的開始。 –

回答

7

望着VBA幫助值不能"xlLeft", "xlBottom"xlLeft, xlBottom,即不帶引號 - 他們是整型常量。

+0

Aaaahhhh,你陛下,是個天才。非常感謝。 – Kayote

0

RTFM。從幫助:

此屬性的值可以設置爲以下 常量之一:

xlBottom xlCenter xlDistributed xlJustify xlTop

0
根據MSDN

,屬性值必須是這些中的一個:

水平:

  • xlCenter
  • xlDistributed
  • xlJustify
  • xlLeft
  • xlR​​ight

垂直:

  • xlBottom
  • xlCenter
  • xlDistributed
  • xlJustify
  • xlTop