首页 > 解决方案 > 将输入框变量从一个子传递到另一个

问题描述

我正在阅读另一个不需要全球声明的帖子。

我有一个 Sub 要求用户输入一个值,在另一个 Sub 中,我使用输入的值根据他们的输入调用其他 Sub。

我在我的例子中很接近吗?谢谢

Option Explicit

Sub MonthTest()
Dim strMonth As String

strMonth = InputBox("enter Area here")

Call Test2

End Sub

Sub Test2(strMonth As String)

Select Case strMonth
    Case Is = "82"
        Call Area82
    Case Is = "80"
        Call Area80
    
End Select
End Sub

标签: excelvbastringcallinputbox

解决方案


您必须将变量提供给调用函数,否则它不知道在哪里寻找它。

更改:调用 Test2 为:调用 Test2 strMonth


推荐阅读