我试图创建一个Excel函数,该函数将以我请求的任何形式将它告诉它的任何范围加粗。不幸的是,我只是在正确传递变量并获得这个结果方面取得了部分成功。当然,没有人喜欢一个部分,所以有人可以让我知道我错过了什么。Excel VBA - 将参数传递给某个函数
Sub Macro1()
On Error Resume Next
'Create & reset testing area.
Range("A1:C6").value = "A"
Range("A1:C6").Font.Bold = False
[b2].Select
'The two lines below call the function perfectly and the cells are bolded without issue
Text_bold ([a1])
Text_bold (Cells(2, 1))
'However, the party stops there as the following code errors out.
Text_bold ([b1].Address)
Text_bold (Selection)
Text_bold (Range("B3"))
'Similarly, the below fails as well...
Text_bold (Range("B4:C4"))
'And even less surprising, the following also refuses to assist in the endeavor...
Text_bold (Application.Union(Range("B5:C5"), Range("B6:C6")))
End Sub
Function Text_bold(x As Range)
'MsgBox VarType(x)
x.Font.Bold = True
End Function
请帮忙。
更多的了解,我认为这是有帮助的注意,那些失败的行失败,因为Range对象提供Range.Value而不是作为对象本身 – serakfalcon
@serafalcon传递,是指出。谢谢。 –
另外,如果您尝试使用不带调用的圆括号调用多参数函数,则会出现语法错误,如:FunctionX(param1,param2) –