2015-08-13 81 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