Reputation: 1
My original problem was finding out how to separate a file with 12000 rows into individual files with 1000 rows and keep the header. I found a great Q&A that does just that (with only one adjustment to number of rows), the link is here: How to split spreadsheet into multiple spreadsheets with set number of rows?
The only thing I need is for the script to save the files down as CSVs rather than Worksheets, but I can't see anything obvious in the script that defines the file type for me to change. FYI, I'm very new to this!
Thanks in advance
Upvotes: 0
Views: 526
Reputation: 3022
As mentioned by @vba4all in the comments above, the expression for Workbook.SaveAs
is
expression .SaveAs(FileName, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution, AddToMru, TextCodepage, TextVisualLayout, Local)
You can visit this msdn article to read more about it.
To save the workbook as csv, you have to use
ActiveWorkbook.SaveAs Filename:="C:\Test.csv", FileFormat:=xlCSV
Please note that when you save the workbook as a csv with or without code, Excel will prompt you for confirmation. To avoid that you can set Application.DisplayAlerts
to False
Here is an example
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="C:\Test.csv", FileFormat:=xlCSV
Application.DisplayAlerts = True
To read more about file formats, you may want to see this msdn link
Upvotes: 3