在 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 - Excel VBA - 将参数传递给属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31987070/