Hello!
I open an Excel file with the VBA code below using a variable called "Filename".
' File filters
Filter = "Excel Workbook (*.xlsx,*xlsx,Excel Makro-enabled Workbook (*.xlsm),*.xlsm,Excel 97-2003 Workbook (*.xls),*.xls,"
' Set Dialog Caption
Title = "Select a File to Open"
With Application
' Set File Name to selected File
Filename = .GetOpenFilename(Filter, FilterIndex, Title)
End With
' Exit on Cancel
If Filename = False Then
MsgBox "No file was selected."
Exit Sub
End If
' Open File
Workbooks.Open Filename
How can I close the file opened with the variable "Filename"? I have tried something like below without success.
Workbooks(Filename).Close Savechanges:=False
Grateful for any help
Kind regards
I open an Excel file with the VBA code below using a variable called "Filename".
' File filters
Filter = "Excel Workbook (*.xlsx,*xlsx,Excel Makro-enabled Workbook (*.xlsm),*.xlsm,Excel 97-2003 Workbook (*.xls),*.xls,"
' Set Dialog Caption
Title = "Select a File to Open"
With Application
' Set File Name to selected File
Filename = .GetOpenFilename(Filter, FilterIndex, Title)
End With
' Exit on Cancel
If Filename = False Then
MsgBox "No file was selected."
Exit Sub
End If
' Open File
Workbooks.Open Filename
How can I close the file opened with the variable "Filename"? I have tried something like below without success.
Workbooks(Filename).Close Savechanges:=False
Grateful for any help
Kind regards