0

The vba is to copy a range --> create a new workbook --> save it as csv, I managed to reach the below, but it opens too many workbooks, and it keeps them opened even after saving them as csv

I've tried the close thing, but its still not working, what can I do to stop this :(

        Columns("A:F").Select
        Selection.Copy

        Workbooks.Add
        ActiveSheet.Paste

        Dim wbNew As Workbook
        Dim strFileName As String

        With ActiveSheet
            strFileName = .Range("A2").Value
            .Copy
        End With

        Set wbNew = ActiveWorkbook

        wbNew.SaveAs ThisWorkbook.Path & "\" & strFileName, FileFormat:=xlCSV, CreateBackup:=False

            Application.DisplayAlerts = False

        ActiveWorkbook.Close

        Workbooks("Paul_Automation_Project_Ver2.xlsm").Activate

        Next

    End Sub
braX
  • 11,506
  • 5
  • 20
  • 33
  • You need to learn how to use workbook objects that get set when you open them and can then later to be used to close them instead of relying on what is active at the time. – braX Mar 12 '20 at 00:49
  • refer [This](https://stackoverflow.com/questions/44771525/convert-xslx-to-csv-using-vba/44772070#44772070) – Dy.Lee Mar 12 '20 at 01:01
  • Have you tried `wbNew.CLose` instead of `ActiveWorkbook.Close` – kiatng Mar 12 '20 at 02:33
  • @kiating yes I've tried to use wb.New.Close but it still opens the workbooks, too many, I think the issues is that it it opens a new workbook (xls) then saving it in csv, not csv directly, so it keeps on the xls one opened, and save another one as csv – Hany Shaker Mar 12 '20 at 08:10

0 Answers0