Showing posts with label excel macro export. Show all posts
Showing posts with label excel macro export. Show all posts

Friday, August 31, 2018

Export and save multiple worksheet as new workbook in excel


If you have multiple excel sheet in a workbook and want to export and save all sheet to individual workbook then just follow below instructions-

Open Visual basic editor by pressing alt+F11
On project window at left side => right click on project => insert=>Module.
now paste below code. read comments and set your parameter.

Sub exportcsv()
Dim ws As Worksheet
Dim path As String

path = ActiveWorkbook.path & "\" & Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name, ".") - 1)
For Each ws In Worksheets
    ws.Activate
    ActiveWorkbook.SaveAs Filename:=path & "_" & ws.Name & ".csv", FileFormat:=xlCSV, CreateBackup:=False
Next
End Sub