I have code below to open a workbook in C:\extract and to copy the data
The code works well, but need it amended so to limit the number of files to only contain New Vehicles.csv for eg BR1 New Vehicles Sales Report.csv so to make it easier for the user to select the correct file
It would be appreciated if someone could kindly amend my code
The code works well, but need it amended so to limit the number of files to only contain New Vehicles.csv for eg BR1 New Vehicles Sales Report.csv so to make it easier for the user to select the correct file
It would be appreciated if someone could kindly amend my code
Code:
Sub Open_NV_Workbook()
ChDir ("C:\extract")
With Sheets("New Vehicles")
.Range("A1:AM1500").ClearContents
End With
Dim nb As Workbook, ts As Worksheet, A As Variant
Dim rngDestination As Range
Set ts = ActiveSheet
With Sheets("New Vehicles")
.Select
End With
On Error Resume Next
Set rngDestination = Application.Range("'new vehicles'!A1")
On Error GoTo 0
If rngDestination Is Nothing Then Exit Sub 'User canceled
MsgBox ("Select New Vehicle Report")
A = Application.GetOpenFilename
If A = False Or IsEmpty(A) Then Exit Sub
Application.ScreenUpdating = False
Set nb = Workbooks.Open(Filename:=A, local:=True)
ThisWorkbook.Activate
nb.Sheets(1).Range("A:AM").Copy
rngDestination.PasteSpecial Paste:=xlPasteValues
rngDestination.PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
nb.Close savechanges:=False 'Close the source workbook
End Sub