Below code snippet activates the open dialog box prompting the user to select an excel file.
I would like to tweak this snippet as follows:
(1) the filter should include xls, xlsx as well as xlsm - files
(2) The inital open dialog is to point to the following path as a constant: 'C:\MyFile\Data'
Help is much appreciated.
Thank you very much in advance.
Dim customerBook As Workbook
Dim filter As String
Dim caption As String
Dim customerFilename As String
Dim customerWorkbook As Workbook
Dim targetWorkbook As Workbook
' active workbook is the target
Set targetWorkbook = Application.ActiveWorkbook
' get the customer workbook
filter = "Excel files (*.xlsx),*.xlsx"
'The open dialog is to point to the following path as a constant: C:\MyFile\Data
caption = "Please Select an input file "
customerFilename = Application.GetOpenFilename(filter, , caption)
If customerFilename = False Then
MsgBox "No File specified.", vbExclamation, "ERROR"
'Filter should be only xls and xlsx files
' If Cancel is pressed then abort the whole macro
Set customerWorkbook = Application.Workbooks.Open(customerFilename)