Export Multiple Excel Sheets To CSV using VBA

To export multiple Excel sheets to CSV files using VBA, you can use the following code. This code will save each sheet in the active workbook as a separate CSV file in the same folder where the Excel file is located:

Sub ExportSheetsToCSV()
    Dim ws As Worksheet
    Dim FilePath As String
    Dim FileName As String
    
    ' Get the folder path where the Excel file is located
    FilePath = ThisWorkbook.Path
    
    ' Loop through all worksheets in the active workbook
    For Each ws In ThisWorkbook.Worksheets
        ' Generate a file name based on the sheet name
        FileName = FilePath & "\" & ws.Name & ".csv"
        
        ' Save the sheet as CSV
        ws.SaveAs FileName:=FileName, FileFormat:=xlCSV
    Next ws
    
    ' Display a message when done
    MsgBox "Sheets have been exported to CSV files in " & FilePath, vbInformation
End Sub

Software Engineer | Ethical Hacker & Cybersecurity...

Md Obydullah is a software engineer and full stack developer specialist at Laravel, Django, Vue.js, Node.js, Android, Linux Server, and Ethichal Hacking.