我的模块看起来像这样
第一个模块..
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 SubI 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 SubIn 2nd module, just use the name Directory wherever you need it. Example:
MsgBox "The directory path is " & Directory
更多推荐
运行调用该模块的程序后,在其他模块中访问模块的变量?
发布评论