Forum Discussion

catherine9910's avatar
catherine9910
Brass Contributor
Jul 24, 2021
Solved

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...
  • HansVogelaar's avatar
    Jul 24, 2021

    catherine9910 

    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

Resources