reuben_rambo
New Member
- Joined
- Mar 13, 2023
- Messages
- 6
- Office Version
- 365
- 2021
- 2019
- Platform
- Windows
Dear forum and VBA experts:
I came across a post here:
Saving multiple sheets in multiple workbooks to CSV with file name
The VBA code runs a macro on all EXCEL FILE (XLSM) in a folder and exports all the sheets within those files out as a .csv
My current VBA code runs a macro on only ONE excel file (XLSM) that must be opened first, where it exports all those files as a .csv where the CSV file output is solely based on the worksheet name in the XLSM file.
QUESTION
Is it possible to amend the VBA macro (written below) so that it can:
[1] Identify the folder where all the excel files [XLSM] are located; and then
[2] Sequentially opens each XLSM file in the folder identified in [1] and saves each worksheet as a CSV file with naming convention “workbook name_worksheet name.csv”
Thanks,
Reuben
What the current VBA code does?
It saves the worksheets as CSV files into a particular folder with the CSV file names are associated with the exact worksheet names.
To run the VBA code, you must open the XLSM file and then run the macro “SaveWorksheetsasCSV”
THE VBA CODE
Public Sub SaveWorksheetsAsCsv()
Dim xWs As Worksheet
Dim xDir As String
Dim folder As FileDialog
Set folder = Application.FileDialog(msoFileDialogFolderPicker)
If folder.Show <> -1 Then Exit Sub
xDir = folder.SelectedItems(1)
For Each xWs In Application.ActiveWorkbook.Worksheets
xWs.SaveAs xDir & "\" & xWs.Name, xlCSV
Next
End Sub
Thanks, I hope someone has a solution for this. I would be immensely grateful if someone is able to post a solution here.
Best,
Reuben
I came across a post here:
Saving multiple sheets in multiple workbooks to CSV with file name
The VBA code runs a macro on all EXCEL FILE (XLSM) in a folder and exports all the sheets within those files out as a .csv
My current VBA code runs a macro on only ONE excel file (XLSM) that must be opened first, where it exports all those files as a .csv where the CSV file output is solely based on the worksheet name in the XLSM file.
QUESTION
Is it possible to amend the VBA macro (written below) so that it can:
[1] Identify the folder where all the excel files [XLSM] are located; and then
[2] Sequentially opens each XLSM file in the folder identified in [1] and saves each worksheet as a CSV file with naming convention “workbook name_worksheet name.csv”
Thanks,
Reuben
What the current VBA code does?
It saves the worksheets as CSV files into a particular folder with the CSV file names are associated with the exact worksheet names.
To run the VBA code, you must open the XLSM file and then run the macro “SaveWorksheetsasCSV”
THE VBA CODE
Public Sub SaveWorksheetsAsCsv()
Dim xWs As Worksheet
Dim xDir As String
Dim folder As FileDialog
Set folder = Application.FileDialog(msoFileDialogFolderPicker)
If folder.Show <> -1 Then Exit Sub
xDir = folder.SelectedItems(1)
For Each xWs In Application.ActiveWorkbook.Worksheets
xWs.SaveAs xDir & "\" & xWs.Name, xlCSV
Next
End Sub
Thanks, I hope someone has a solution for this. I would be immensely grateful if someone is able to post a solution here.
Best,
Reuben