VBA excel传回参数

时间:2013-11-23 17:50:46

标签: excel vba excel-vba

好的我想为这个宏添加一些东西

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

  

案例就像是,我希望我的sub传递找到的参数   Search()到getInput()然后getInput()返回找到的参数   搜索()

我应该添加类似搜索的内容(ByVal找到布尔值)吗?

1 个答案:

答案 0 :(得分:2)

如果要返回值,则应将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