Excel Excel VBA (Saving as A CSV)


Joined
Feb 26, 2013
Messages
12
Reaction score
0
I have a sheet that runs a macro to save the file into a directory as a csv file using the now function to receive a timestamp.

Below is a copy of the code used;

Private Sub saveasdt()
Dim dt As String
Dim location As String
dt = Now
Sheet3.SaveAs Filename:="Q:\SPREAD\Billy\" & dt & ".csv", FileFormat:=xlCSV
End Sub

An error appears when the last line of code is run;

Run-time error '1004':
Application-defined or object-defined error.

Any ideas why there is an error and can anyone provide alternative code for this.

Cheers in advance,

Billy
 
Last edited:
Ad

Advertisements

Joined
Nov 11, 2012
Messages
17
Reaction score
1
You can't saveas a date, but you can format the string to look like a date, for example.
Code:
Private Sub saveasdt()
  Dim dt As String
  Dim location As String
  dt = Format(Now, "MMMM-DD-YyyY")
  Sheet3.SaveAs Filename:="C:\Test2\" & dt & ".csv", FileFormat:=xlCSV
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top