0% found this document useful (0 votes)
10 views2 pages

File Merge and Split

The document contains three VBA macros for Excel: one to export each worksheet in a workbook to separate CSV files, another to save each worksheet as individual XLSX files, and a third to combine multiple sheets into a single master sheet with page breaks. The macros automate the processes of copying, saving, and deleting sheets as required. Additionally, it includes a link to a Microsoft forum for further assistance with opening multiple CSV files as sheets in a single workbook.

Uploaded by

Ashish Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

File Merge and Split

The document contains three VBA macros for Excel: one to export each worksheet in a workbook to separate CSV files, another to save each worksheet as individual XLSX files, and a third to combine multiple sheets into a single master sheet with page breaks. The macros automate the processes of copying, saving, and deleting sheets as required. Additionally, it includes a link to a Microsoft forum for further assistance with opening multiple CSV files as sheets in a single workbook.

Uploaded by

Ashish Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

To split sheets to csv files

Sub ExportSheetsToCSV()
Dim xWs As Worksheet
Dim xcsvFile As String
For Each xWs In Application.ActiveWorkbook.Worksheets
xWs.Copy
xcsvFile = CurDir & "\" & xWs.Name & "11.csv"
Application.ActiveWorkbook.SaveAs Filename:=xcsvFile, _
FileFormat:=xlCSV, CreateBackup:=False
Application.ActiveWorkbook.Saved = True
Application.ActiveWorkbook.Close
Next
End Sub

To split sheets to xlsx files

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

https://answers.microsoft.com/en-us/msoffice/forum/all/open-multiple-csv-as-
multiple-sheets-in-single/6bfea460-2474-4fa7-bbbf-8b89874870ab

merge multiple sheets into one

Sub CombineSheetswithPageBrakes()

Dim MasterSh As Worksheet

Dim QSh As Worksheet

Dim break As String

Application.ScreenUpdating = False

Application.DisplayAlerts = False

Set MasterSh = ThisWorkbook.Sheets.Add

MasterSh.Name = "Master"
For Each QSh In ThisWorkbook.Sheets

If QSh.Name <> "Master" Then

With MasterSh

''' Find the Page Break address

break = .UsedRange.Offset(MasterSh.UsedRange.Rows.Count + 2).Resize(1,


1).Address

'' Inserting the new page break

.HPageBreaks.Add Before:=.Range(break)

End With

'' Copy/Paste (Transfer) the values form the other sheets to Master
sheet

QSh.UsedRange.Copy
MasterSh.UsedRange.Offset(MasterSh.UsedRange.Rows.Count + 2).Resize(1, 1)

'' Delete the sheet after transfer it to master sheet

QSh.Delete

End If

Next QSh

MasterSh.Rows("1:3").Delete

Application.ScreenUpdating = True

Application.DisplayAlerts = True

End Sub

You might also like