Last active
March 1, 2019 21:27
-
-
Save martinctc/fc6ed292c77e9f13ba186c049a834235 to your computer and use it in GitHub Desktop.
Save Worksheets in Excel file to CSV files (not my code) #Excel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub SaveWorksheetsAsCsv() | |
Dim WS As Excel.Worksheet | |
Dim SaveToDirectory As String | |
Dim CurrentWorkbook As String | |
Dim CurrentFormat As Long | |
CurrentWorkbook = ThisWorkbook.FullName | |
CurrentFormat = ThisWorkbook.FileFormat | |
' Store current details for the workbook | |
SaveToDirectory = "H:\test\" | |
For Each WS In ThisWorkbook.Worksheets | |
Sheets(WS.Name).Copy | |
ActiveWorkbook.SaveAs Filename:=SaveToDirectory & ThisWorkbook.Name & "-" & WS.Name & ".csv", FileFormat:=xlCSV | |
ActiveWorkbook.Close savechanges:=False | |
ThisWorkbook.Activate | |
Next | |
Application.DisplayAlerts = False | |
ThisWorkbook.SaveAs Filename:=CurrentWorkbook, FileFormat:=CurrentFormat | |
Application.DisplayAlerts = True | |
' Temporarily turn alerts off to prevent the user being prompted | |
' about overwriting the original file. | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment