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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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,213,520
Messages
6,114,101
Members
448,548
Latest member
harryls

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