How do I pass the filename selected into another module?

Mr Denove

Active Member
Joined
Jun 8, 2007
Messages
446
Morning all,

Im still learning my way through VBA and hoping for some help and guidance on this problem please.

I have a module (see blow) which selects the file to be used. Another module is used to save another file and I need to use the date which is in the filename to name the being saved.

How do I pass the name of the file selected in the below code into the other module?

Any help is greatly appreciated. Thanks in advance.
Stuart


Code:
Sub CopySourceExtract()
Dim wb1 As Workbook, wb2 As Workbook
Dim Ret1, Ret2
Dim LastRow As Long
    
Dim Filename As Variant
    


Sheets("Extract").Cells.AutoFilter

Application.ScreenUpdating = False
     
Application.DisplayAlerts = False

Application.DisplayStatusBar = False

ActiveSheet.DisplayPageBreaks = False

Application.CutCopyMode = False

Application.Calculation = xlCalculationManual

Application.EnableEvents = False
 
Set wb1 = ActiveWorkbook
        
    ChDir "\\Code that links the folders to file etc etc\"
  
    Ret2 = Application.GetOpenFilename("Excel Files (*.csv*), *.csv*", _
    , "Please select file")
If Ret2 = False Then End
    
Dim strPath As String
strPath = Ret2

Dim strFile As String
strFile = Right(strPath, Len(strPath) - InStrRev(strPath, "\"))
Filename = CreateObject("Scripting.FileSystemObject").GetBaseName(strFile)
    
Set wb2 = Workbooks.Open(Ret2, Local:=True, ReadOnly:=True)
ThisWorkbook.Activate
More code......
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
You'd need:

Code:
Public FilePath as String

at the top of a normal module, for example, and then in the first of your routines, assign the chosen file name to FilePath.
 
Upvote 0

Forum statistics

Threads
1,215,417
Messages
6,124,791
Members
449,188
Latest member
Hoffk036

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top