【问题标题】:VBA excel Passing back parameterVBA excel 传回参数
【发布时间】:2013-11-24 02:36:18
【问题描述】:

好的,我想在这个宏中添加一些东西

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 传递 found 参数 Search() 到 getInput() 然后 getInput() 将 found 参数返回给 搜索()

我是否应该添加类似 search(ByVal found as boolean) 之类的内容?

【问题讨论】:

  • 您的a 子中的a 是什么?并且您的循环语法无效..
  • 函数可以返回值。你试过了吗?

标签: vba excel


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-29
    • 2010-09-23
    相关资源
    最近更新 更多