VBA excel 传回参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20165766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA excel Passing back parameter
提问by Aldin
Okay I want to add something to this macro
好的,我想向这个宏添加一些东西
Sub Search()
Inputbox myInput
found = false
loop
Call getInput (myInput) '~> check multiple files
end loop
If found = false
'DO something
End if
End sub
Sub getInput(ByVal inputVar As String, ByVal Input as Boolean)
If a = inputVar Then
found = true '~> I want to pass this parameter back to search
End If
End sub
The case is like, I want my sub to pass the foundparameter from Search() to getInput() and then getInput() return the foundparameter to Search()
情况就像,我希望我的子程序将找到的参数从 Search() 传递给 getInput(),然后 getInput() 将找到的参数返回给 Search()
Should I add something like search(ByVal found as boolean) ?
我应该添加类似 search(ByVal found as boolean) 的内容吗?
采纳答案by Sam
if you want to return a value, then you should change the getInput Sub to a function as they can return values.
如果你想返回一个值,那么你应该将 getInput Sub 更改为一个函数,因为它们可以返回值。
Sub Search()
Dim found As Boolean
InputBox myInput
found = checkInput(myInput)
If found = False Then
'DO something
End If
End Sub
Function checkInput(inputVar As String) As Boolean
Dim result As Boolean
'do your checking here and set result
'return the result
checkInput = result
End Function