1.插入一个模块或在已有的模块最上面一行定义一个
全局变量比如: Public iFileName As String
2.在这个工作薄的其他模块中都可以引用这个变量
比如:(先执行一次test1,再执行test2)
Sub test1()
'打开一个选择文件的对话框
iFileName = Application.GetOpenFilename
End Sub
Sub test2()
If iFileName = "False" Then
MsgBox "没有选择文件!"
Else
wz = InStrRev(iFileName, "\")
Path = Left(iFileName, wz)
fname = Right(iFileName, Len(iFileName) - wz)
MsgBox "选择的文件名为:" & fname & vbCrLf & "路径为:" & Path
End If
End Sub