Jul 23 2021 05:04 PM - edited Jul 23 2021 05:45 PM
Hey Everyone,
I need your help again. I have Sales data that I need to be copied and pasted into a Hot Spot workbook (both are excel) via Macro. The only problem is the name of the Sales data workbook changes each day. However, it is in the same file location/folder.
7-23-2021.csv
7-22-2021.csv
7-21-2021.csv and so on.
How do I write my VBA code to open a set folder then let me open a different file each time to copy and paste into my Hot Spot workbook?
Jul 24 2021 03:44 AM
SolutionI hope you can use the code below as starting point.
Sub ProcessCSV()
' Change path as needed but keep the \ at the end
Const strPath = "C:\MyFolder\"
Dim strFile As String
Dim wbkSales As Workbook
Dim wbkCSV As Workbook
With Application.FileDialog(1) ' msoFileDialogOpen
.Filters.Clear
.Filters.Add "CSV Files (*.csv)", "*.csv"
.InitialFileName = strPath & "*.csv"
If .Show Then
strFile = .SelectedItems(1)
Else
Beep
Exit Sub
End If
End With
Set wbkSales = ActiveWorkbook
Set wbkCSV = Workbooks.Open(Filename:=strFile)
' Code to copy goes below
' ...
wbkCSV.Close SaveChanges:=False
End Sub
Jul 26 2021 11:44 AM
Jul 24 2021 03:44 AM
SolutionI hope you can use the code below as starting point.
Sub ProcessCSV()
' Change path as needed but keep the \ at the end
Const strPath = "C:\MyFolder\"
Dim strFile As String
Dim wbkSales As Workbook
Dim wbkCSV As Workbook
With Application.FileDialog(1) ' msoFileDialogOpen
.Filters.Clear
.Filters.Add "CSV Files (*.csv)", "*.csv"
.InitialFileName = strPath & "*.csv"
If .Show Then
strFile = .SelectedItems(1)
Else
Beep
Exit Sub
End If
End With
Set wbkSales = ActiveWorkbook
Set wbkCSV = Workbooks.Open(Filename:=strFile)
' Code to copy goes below
' ...
wbkCSV.Close SaveChanges:=False
End Sub