PDA

View Full Version : Save a file as csv with date



pcarmour
10-24-2014, 07:45 AM
HI,
I am currently saving a file as an Excel Workbook (*XLSX) with today's date using this VBA code:

ActiveWorkbook.SaveAs Filename:="M:\Beaufort ACS\BACS Operations\Operations\Additional Prices\" & Valuation & "Additional Prices " & Format(Date, "ddmmyyyy")

I want to change this to now be able to save the file with today's date but as a CSV file - CSV (comma delimited) (*.CSV)
But can't find the correct way to do it.

Any help as always is very much appreciated.

I am working with Windows Home Premium version 6.1.7601 SP 1 Build 7601and Excel version 14.0.6123.5001 (32 bit)

ashleyuk1984
10-24-2014, 08:45 AM
HI,
I am currently saving a file as an Excel Workbook (*XLSX) with today's date using this VBA code:

I want to change this to now be able to save the file with today's date but as a CSV file - CSV (comma delimited) (*.CSV)
But can't find the correct way to do it.

Any help as always is very much appreciated.

I am working with Windows Home Premium version 6.1.7601 SP 1 Build 7601and Excel version 14.0.6123.5001 (32 bit)

Try this.


ActiveWorkbook.SaveAs Filename:="M:\Beaufort ACS\BACS Operations\Operations\Additional Prices\" & Valuation & "Additional Prices " & Format(Date, "ddmmyyyy") & ".csv", FileFormat:=xlCSV

FileFormat:=xlCSV might not be required. I didn't test.

lpeless
10-17-2019, 05:23 PM
I know this is a few years after but it's the same topic. The fix that was suggested isn't working. Here is my code.
ActiveWorkbook.SaveAs Filename:= _
"C:\Users\LKPeless\Downloads\NWEA EP" & Format(Now(), "MM-DD-YY")& ".csv", FileFormat:=xlCSV,
CreateBackup:=False

It isn't working. It is saying Compile error: Expected: named parameter.
Please assist and I thank you in advance.

ashleyuk1984
10-17-2019, 05:38 PM
I was able to save a blank file using your code.

Is the error message appearing at exactly that part of the code?? I don't see why it would be?

lpeless
10-17-2019, 05:46 PM
I'm new to the debugging phase. When I run it it highlights in the VBA space from ActiveWorkbook to the FileFormat:=xlCSV,

Only CreateBackup:=False is unhighlighted. It all turns red though. the new error message I get is Compile error: Syntax error. I'm not sure if this helps you out at all.

ashleyuk1984
10-17-2019, 06:23 PM
Interesting... That "CreateBackup:=False" is part of the same line... So that would indicate to me that you have a line break.

Make sure that your "CreateBackup" is next to FileFormat:=xlCSV,

Or just copy this, and replace your code:

ActiveWorkbook.SaveAs Filename:= _
"C:\Users\LKPeless\Downloads\NWEA EP" & Format(Now(), "MM-DD-YY")& ".csv", FileFormat:=xlCSV, CreateBackup:=False

lpeless
10-17-2019, 07:25 PM
That did the trick. Thank you so much for your help. You have helped save me time every day by this working. I truly appreciate it.