+ Reply to Thread
Results 1 to 3 of 3

Excel Save as CSV file

  1. #1
    Registered User
    Join Date
    03-08-2016
    Location
    Newport
    MS-Off Ver
    2010
    Posts
    17

    Excel Save as CSV file

    I need to save a copy of the worksheet I'm using as a CSV file. I the save name to be the date and users name, I've set up variables to get this information however i keep getting a Run-time error '1004'; Application-defined or object-defined error message and it will not work.

    Code I'm using is:

    Sub SaveCSV()
    rundate = DateTime.Now
    runname = Application.UserName
    savename = rundate & runname
    sfilename = ActiveWorkbook.Path & "\" & savename & ".csv"

    ActiveWorkbook.Save

    ActiveWorkbook.SaveAs Filename:=sfilename, FileFormat:=xlCSV
    Application.DisplayAlerts = True
    End Sub

    Can anyone point me in the right direction as to what the problem is and how to fix it please?

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,935

    Re: Excel Save as CSV file

    Likely issue is caused by rundate format. In most cases, datetime format contains illegal character for a file name.

    Try something like below.
    Please Login or Register  to view this content.

  3. #3
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,505

    Re: Excel Save as CSV file

    Perhaps add
    Please Login or Register  to view this content.
    at beginning
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to create and save excel file from a master excel file
    By sunny81 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-16-2017, 10:29 PM
  2. Macro to create and save excel file from a master excel file
    By sunny81 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-16-2017, 09:49 PM
  3. [SOLVED] Macro to open Excel file, run other macros save, and close file & repeat.
    By Ronnet2 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-08-2015, 09:47 AM
  4. Replies: 1
    Last Post: 09-05-2013, 02:39 PM
  5. Converting excel 2003 file ext macro file-save code to reflect excel 2007 exts
    By pmanoloff in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-20-2013, 12:17 PM
  6. Replies: 1
    Last Post: 01-16-2013, 02:02 AM
  7. 'document not saved' for 'save' or 'save as' an EXCEL file
    By Judy Chuang in forum Excel General
    Replies: 1
    Last Post: 07-11-2005, 06:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1