从2个模块之间拉动variables
我有一个variables,在我的第一个模块,我想在我的第二个模块中使用这个variables。第一个代码是我的variables。
Dateiname = Ord & mNummerGanz & "_" & Name & ".xlsm" ThisWorkbook.SaveAs Filename:=Dateiname
我想在同一个项目的不同模块中使用这个variables。
Windows(Dateiname).Activate
有没有人有build议?
Sub newmodule1() Dim Dateiname As String Dateiname = Ord & mNummerGanz & "_" & Name & ".xlsm" ThisWorkbook.SaveAs Filename:=Dateiname, fileformat:=52 'This is just here to test the variable is stored correctly. msgbox can be removed. MsgBox (Dateiname) Module2.newmodule2 (Dateiname) End Sub Sub newmodule2(Dateiname) 'Again, this is just here to test the variable is stored correctly. msgbox can be removed. MsgBox (Dateiname) Windows(Dateiname).Activate End Sub
在第一个模块的顶部将其定义为Public
。
下面是一个简单的例子… Module
和Sub
名字就是这个例子。
在Module1中 :
Public Dateiname As String Private Sub SaveMyFile() Dateiname = Ord & mNummerGanz & "_" & Name & ".xlsm" ThisWorkbook.SaveAs Filename:=Dateiname End Sub
在Module2中 :
Private Sub MyOtherSub() Windows(Dateiname).Activate End Sub