0

如何通过在其他 sub 中调用 sub 从 sub 中获取 var 值?像

  Sub test()
    Dim a As Integer
    a = 1
  End Sub
  Sub testshow()
    MessageBox.Show(test.a)
  End Sub
4

1 回答 1

1

在 VBA(您的标签状态)中,您需要更改SubFunction

Function test()
    Dim a As Integer
    a = 1
    test = a
End Function

Sub testshow()
   MsgBox test
End Sub

评论后编辑:如果您使用多个变量,则:

Function test(whichVar)
    Dim a As Integer
    If whichVar = 1 then
        a = 100
    ElseIf whichVar = 2 Then
        a = 200
    'etc...
    End if

    test = a
End Function

Sub testshow()
   MsgBox test(2)    'will give you 200
End Sub
于 2013-03-28T06:36:09.360 回答