Forum Discussion
catherine9910
Jul 24, 2021Brass Contributor
Macro Copy Help
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 work...
- Jul 24, 2021
I 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
HansVogelaar
Jul 24, 2021MVP
I 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
catherine9910
Jul 26, 2021Brass Contributor
Thank you so much Hans that worked perfectly. You're the man!