Consulting

Results 1 to 7 of 7

Thread: Save a file as csv with date

  1. #1
    VBAX Contributor
    Joined
    Nov 2012
    Location
    Billericay, Essex
    Posts
    145
    Location

    Save a file as csv with date

    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)
    Regards, Peter.

  2. #2
    Quote Originally Posted by pcarmour View Post
    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.

  3. #3
    VBAX Newbie
    Joined
    Oct 2019
    Posts
    3
    Location
    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.

  4. #4
    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?

  5. #5
    VBAX Newbie
    Joined
    Oct 2019
    Posts
    3
    Location
    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.

  6. #6
    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

  7. #7
    VBAX Newbie
    Joined
    Oct 2019
    Posts
    3
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •