When calling subs from a main sub, how do we handle variables? For example, I would like to declare and set a filename variable just once (selected by the user on the fly) in the main sub and re-use that variable for the subsequent subs that perform different operations on the input file. However, I take it each time Excel gets to an End Sub command it promptly forgets the variable and I will have to have the user select the input file over and over in each subsequent Sub.
Ideally, I'd like to do the following:
Ideally, I'd like to do the following:
VBA Code:
Sub MonthlyImport()
Dim MonthlyDataFile As Variant
MonthlyDataFile = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls*), *.xls*")
Call Subroutine1
Call Subroutine2
Call Subroutine3
End Sub
Sub Subroutine1()
'Perform operations on MonthlyDataFile
End Sub
Sub Subroutine2()
'Perform more operations on MonthlyDataFile
End Sub
Sub Subroutine3()
'Perform yet more operations on MonthlyDataFile
End Sub