使用character作为函数的参数

时间:2014-12-01 21:11:03

标签: vba excel-vba excel

我希望只能将q作为参数传递给函数,这样用户就不必输入字符串"q"

我在模块中定义了一个函数

Function doThis(val As Variant)

  MsgBox CStr(val)

  ' Here is a comparison of val with other strings and additional code

End

我从我的工作表中调用它:

=doThis(q)

消息框返回

Error 2029

我已尝试使用String和Boolean作为值类型,但只有variant会触发该函数。

是否可以收到q作为参数?

1 个答案:

答案 0 :(得分:2)

非常简单。首先为 q

创建定义名称

enter image description here

其次在标准模块中:

Function doThis(val As Variant)
    MsgBox CStr(val)
    doThis = ""
End Function

最后在工作表中:

enter image description here

相关问题