Excel VBA-将参数传递给属性
在Excel VBA中,我试图将参数值传递给属性“VerticalAlignment”。我得到的错误是:“无法设置Range类的HorizontalAlignment属性”。显然,问题在于“horzAlign”和“vertAlign”值,但是,什么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
' 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
- xlCenter
- xlDistributed
- xlJustify
- xlLeft
- xlRight
- xlBottom
- xlCenter
- xlDistributed
- xlJustify
- xlTop
horzAlign
和vertAlign
的可能值是什么?埃博拉·保罗已经回答了这个问题。它是一个整数常量。Thanks@psychicebola:没关系:它们不应该是字符串。您的horzAlign
和vertAlign
的可能值是多少?埃博拉·保罗已经回答了。它是一个整数常量。Thanks@psychicebola:无所谓:它们不应该是开始时的字符串。