Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel VBA-将参数传递给属性_Vba_Excel - Fatal编程技术网

Excel VBA-将参数传递给属性

Excel VBA-将参数传递给属性,vba,excel,Vba,Excel,在Excel VBA中,我试图将参数值传递给属性“VerticalAlignment”。我得到的错误是:“无法设置Range类的HorizontalAlignment属性”。显然,问题在于“horzAlign”和“vertAlign”值,但是,什么 ' Merge the range & horizontal & vertical ' alignment as per arguments Sub mergeCellsWithLeftAlign(ByVal curRange As

在Excel VBA中,我试图将参数值传递给属性“VerticalAlignment”。我得到的错误是:“无法设置Range类的HorizontalAlignment属性”。显然,问题在于“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
这在另一个过程中被调用,如下所示:

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

查看VBA帮助时,值不能是
“xlLeft”,“xlBottom”
,而是
xlLeft,xlBottom
,即没有引号-它们是整数常量。

查看VBA帮助时,值不能是
“xlLeft”,“xlBottom”
,而是
xlLeft,xlBottom
,也就是说,没有引号-它们是整数常量。

RTFM。从帮助中:

此属性的值可以设置为以下值之一 常数:

xlBottom xlCenter xlDistributed xlJustify xlTop


RTFM。从帮助中:

此属性的值可以设置为以下值之一 常数:

xlBottom xlCenter xlDistributed xlJustify xlTop


根据msdn,属性值必须是以下值之一:

水平:

  • xlCenter
  • xlDistributed
  • xlJustify
  • xlLeft
  • xlRight
垂直:

  • xlBottom
  • xlCenter
  • xlDistributed
  • xlJustify
  • xlTop

根据msdn,属性值必须是以下值之一:

水平:

  • xlCenter
  • xlDistributed
  • xlJustify
  • xlLeft
  • xlRight
垂直:

  • xlBottom
  • xlCenter
  • xlDistributed
  • xlJustify
  • xlTop

你的
horzAlign
vertAlign
的可能值是什么?埃博拉·保罗已经回答了这个问题。它是一个整数常量。Thanks@psychicebola:没关系:它们不应该是字符串。您的
horzAlign
vertAlign
的可能值是多少?埃博拉·保罗已经回答了。它是一个整数常量。Thanks@psychicebola:无所谓:它们不应该是开始时的字符串。