I have code below that allows a user to limit the selection when browsing for a csv file in C:\Extract
I would like the code to allow the browsing to show files like MGU Parts or Parts MGU and only show the latest modified files like this
Kindly amend my code
I would like the code to allow the browsing to show files like MGU Parts or Parts MGU and only show the latest modified files like this
Kindly amend my code
Code:
Sub Open_Workbook()
ChDir ("C:\extract")
Dim nb As Workbook, tw As Workbook, WS As Worksheet, LR As Long, A As Variant
Dim rngDestination As Range
Dim filename As Variant
Set WS = ThisWorkbook.Sheets("Imported Data")
WS.UsedRange.ClearContents
On Error Resume Next
Set rngDestination = WS.Range("A1")
On Error GoTo 0
If rngDestination Is Nothing Then Exit Sub 'User canceled
With Application.FileDialog(msoFileDialogFilePicker)
.ButtonName = "Select"
With .Filters
.Clear
.Add "CSV Files", "*.csv"
End With
.FilterIndex = 1
.InitialFileName = "C:\Extract\MGU*Part*.csv"
.Title = "Select CSV file"
If .Show = 0 Then Exit Sub
filename = .SelectedItems(1)
End With
Debug.Print filename
Application.ScreenUpdating = False
Dim srcWorkbook As Workbook
Set srcWorkbook = Workbooks.Open(filename:=filename, local:=True)
ThisWorkbook.Activate
srcWorkbook.Sheets(1).Range("A:AM").Copy
rngDestination.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
srcWorkbook.Close SaveChanges:=False
Application.ScreenUpdating = True
End Sub