运行调用该模块的程序后,在其他模块中访问模块的变量? [英] Access a variable of a module in another module after running the program which calls that module?
问题描述
我的模块看起来像这样
第一个模块..
Public Sub Directory_Path()
Dim Directory As String
Directory = InputBox(输入包含文件夹的目录路径这个季度,Last QuarterSecond_Last_Quarter。)
如果Right(Directory,1)=\然后
Directory = Left(Directory,Len(Directory) 1)
End If
End Sub
我打电话给第一个模块第二个模块使用Public Sub Directory_Path()。我想要第一个模块中的目录变量作为第二个模块中的变量...
在第1个模块 - 声明目录作为公开在任何子/功能之外的模块的顶部。该项目中的每个模块现在都可用:
公共目录为String
Sub Directory_Path()
目录= InputBox(输入包含文件夹的目录路径这个季度,最后一个季度Second_Last_Quarter。)
如果右,1)=\then
Directory = Left(Directory,Len(Directory) - 1)
End If
End Sub
在第二个模块中,只需使用名称 Directory
,无论你需要什么。示例:
MsgBox目录路径为&目录
I have an excel file with 2 buttons which access two different modules. Can we access a variable of a module in another module after running the program which calls that module?
My modules look like this
1st module..
Public Sub Directory_Path()
Dim Directory As String
Directory = InputBox("Enter the Directory path that contains folders ""This Quarter"",""Last Quarter"",""Second_Last_Quarter"".")
If Right(Directory, 1) = "\" Then
Directory = Left(Directory, Len(Directory) - 1)
End If
End Sub
I called the the first module in 2nd module using Public Sub Directory_Path() . I want Directory variable in first module to be used as a variable in 2nd module...
In 1st module - declare Directory as Public at top of module outside of any Sub/Function. It's now available to every module in this project:
Public Directory As String
Sub Directory_Path()
Directory = InputBox("Enter the Directory path that contains folders ""This Quarter"",""Last Quarter"",""Second_Last_Quarter"".")
If Right(Directory, 1) = "\" Then
Directory = Left(Directory, Len(Directory) - 1)
End If
End Sub
In 2nd module, just use the name Directory
wherever you need it. Example:
MsgBox "The directory path is " & Directory
这篇关于运行调用该模块的程序后,在其他模块中访问模块的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!