Thursday, December 7, 2017

How to export and save each worksheet as new workbook in Excel

excel - VBA - Saving all worksheets as separate files

if you want to save your multiple excel worksheet as a separate workbook at specific folder then you are right place..

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 Splitbook()
'Updateby20140612
Dim xPath As String
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xWs In ThisWorkbook.Sheets
    xWs.Copy
    Application.ActiveWorkbook.SaveAs Filename:=xPath & "\" & xWs.Name & ".xlsx"
    Application.ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub


=========================
now its time to run your code by pressing F5.
Done!

No comments:

Post a Comment