Reputation: 161
I have a variable which is in my first module and i would like to use this variable in my second module.The first code is my variable.
Dateiname = Ord & mNummerGanz & "_" & Name & ".xlsm"
ThisWorkbook.SaveAs Filename:=Dateiname
And i would like to use this variable in different module in same Project.
Windows(Dateiname).Activate
Does anyone have Suggestion?
Upvotes: 0
Views: 40
Reputation: 413
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
Upvotes: 1
Reputation: 20179
Define it as Public
at the top of your first module.
A simple example is below...the Module
and Sub
names are just made up for the example.
In Module1:
Public Dateiname As String
Private Sub SaveMyFile()
Dateiname = Ord & mNummerGanz & "_" & Name & ".xlsm"
ThisWorkbook.SaveAs Filename:=Dateiname
End Sub
In Module2:
Private Sub MyOtherSub()
Windows(Dateiname).Activate
End Sub
Upvotes: 0