Excel VBA - 将参数传递给属性

Kay*_*ote 1 excel vba excel-vba

在Excel VBA中,我试图将参数值传递给属性'VerticalAlignment'.我得到的错误是:"无法设置Range类的Horizo​​ntalAlignment属性".显然问题在于'horzAlign'和'vertAlign'值,但是,什么?

' 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
Run Code Online (Sandbox Code Playgroud)

这是在另一个程序中调用,如下所示:

Call mergeCellsWithLeftAlign(Range("F10:F11"), "xlLeft", "xlBottom")
Run Code Online (Sandbox Code Playgroud)

Pau*_*vie 7

望着VBA帮助值不能"xlLeft", "xlBottom",但是xlLeft, xlBottom,即不带引号-他们是整型常量.