Dim strPassword as String 'this will hold the password to open the file, if any
Dim varSrcPath as Variant 'this will hold the file path
Dim wbSrc as Workbook 'this is the workbook variable
'browse for source file
varSrcPath = Application.GetOpenFilename(FileFilter:="Csv files (*.csv), *.csv", Title:="Select Source File")
'check if no file was selected
if varSrcPath = False then
MsgBox "No file selected."
GoTo Cleanup
Else:
'if a file was selected, open it
Set wbSrc = Workbooks.Open(Filename:=varSrcPath, Password:=strPassword)
'handler for wrong password error
If Err.Number <> 0 Then
Err.Clear
MsgBox "Wrong Password." & strPassword
GoTo Cleanup
End If
'end error trap
On Error GoTo 0
End If