Macro save as CSV with Date not working

oliviar

Board Regular
Joined
Sep 12, 2010
Messages
184
Hi Guys,

Why does my macro hate me?

Code:
    ChDir "P:\Data\Data Sent"
    ActiveWorkbook.SaveAs Filename:= _
        "P:\Data\Data Sent\AU2011" & Format(Date, “yyyymmdd“) & “.csv”_
        FileFormat:=xlCSV, CreateBackup:=False

I keep getting a syntax error on the FileFormat line.

I am using 2007
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I think you need a space between the underscore and the last quotation mark on the third line:

Code:
    ChDir "P:\Data\Data Sent"
    ActiveWorkbook.SaveAs Filename:= _
        "P:\Data\Data Sent\AU2011" & Format(Date, “yyyymmdd“) & “.csv”[COLOR="Red"][B]_[/B][/COLOR]
        FileFormat:=xlCSV, CreateBackup:=False

Amend to:
Code:
    ChDir "P:\Data\Data Sent"
    ActiveWorkbook.SaveAs Filename:= _
        "P:\Data\Data Sent\AU2011" & Format(Date, “yyyymmdd“) & “.csv”[COLOR="Red"][B] _[/B][/COLOR]
        FileFormat:=xlCSV, CreateBackup:=False

Or:
Code:
    ChDir "P:\Data\Data Sent"
    ActiveWorkbook.SaveAs Filename:= _
        "P:\Data\Data Sent\AU2011" & Format(Date, “yyyymmdd“) & “.csv” FileFormat:=xlCSV, CreateBackup:=False
 
Upvote 0
Edit:
Oops. A space and a comma are needed:
Code:
    ChDir "P:\Data\Data Sent"
    ActiveWorkbook.SaveAs Filename:= _
        "P:\Data\Data Sent\AU2011" & Format(Date, “yyyymmdd“) & “.csv”[COLOR="Red"][B], _[/B][/COLOR]
        FileFormat:=xlCSV, CreateBackup:=False

Or:
Code:
    ChDir "P:\Data\Data Sent"
    ActiveWorkbook.SaveAs Filename:= _
        "P:\Data\Data Sent\AU2011" & Format(Date, “yyyymmdd“) & “.csv”, FileFormat:=xlCSV, CreateBackup:=False
 
Upvote 0
Sigh, but now when I run it is says 'object required'
On the filename line its just **** unhappy.
 
Last edited:
Upvote 0
Okay, I bashed it into this and its working:

Code:
On Error GoTo End1:

  fname = "P:\Data\Data Sent\AU" & Format(Date, "YYYYMMDD") & ".csv"
    ActiveWorkbook.SaveAs Filename:=fname, FileFormat:=xlCSVWindows
    ActiveWorkbook.Close SaveChanges:=False

End1:
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,876
Members
452,949
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top