vba excel将参数从sub传递给sub

时间:2013-11-22 15:23:15

标签: vba

我想将我的输入传递给其他潜艇,例如:

Sub Search()
  Inputbox myInput   '~> this is the variable I want to pass
  Call getInput      '~> I want to pass the variable to this sub
End sub

Sub getInput()
  if a = myInput     '~> from sub Search()
  DO something
End sub

我搜索解决方案并阅读有关ByVal或ByRef的信息,但是我对这个变量放在哪里感到困惑,有人可以提供帮助吗?

1 个答案:

答案 0 :(得分:1)

Sub Search()
  Inputbox myInput   '~> this is the variable I want to pass
  Call getInput (myInput)  '~> Note the variable
End sub

Sub getInput(ByVal inputVar As String)  '~> Note:  You need to specify the datatype
  If a = inputVar Then     '~> Use your parameter here
      'DO something
  End If
End sub