【问题标题】:vba excel passing parameter from sub to subvba excel将参数从子传递到子
【发布时间】:2013-12-07 12:58:56
【问题描述】:

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

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 的信息,但我很困惑将变量放在哪里,有人可以帮忙吗?

【问题讨论】:

    标签: vba


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      • 1970-01-01
      • 2012-12-02
      • 2013-08-24
      • 2017-02-01
      相关资源
      最近更新 更多