+ Reply to Thread
Results 1 to 5 of 5

XLS to CSV with a Date on the filename - using VB

Hybrid View

  1. #1
    Registered User
    Join Date
    02-16-2013
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2003
    Posts
    5

    XLS to CSV with a Date on the filename - using VB

    Hello.

    I have done a fair amount of searching across the various forums and I don't seem to find an answer that directly answers this question:

    I am trying to convert a XLS file to CSV after I complete a simple script that formats numbers correctly in the document (this is so this file can be accessed via "Data Merge" in Adobe InDesign).

    I would like it to be automated that when I run the Macro this automatically spits out the file name as a CSV with a date on the end of the filename. I am running this on various different XLS files so the script would need to be somehow (I really don't know if this is possible) generic so that even if the file is in a different directory it will place the CSV in that directory with that same filename except changed to ".CSV" and having today's date. Example:

    C:\test\text.xls = C:\test\test 1-15-2013.csv

    or
    C:\default\charts\flower.xls = C:\default\charts\flower 1-15-2013.csv

    Thanks for any help or even a nice tap in the right diretion.

    Best,
    Simon

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: XLS to CSV with a Date on the filename - using VB

    'Files in a folder to CSVs
    Here's a macro for creating a CSV version of all sheets in all Excel files in a chosen folder.


    Files to CSVs
    Last edited by JBeaucaire; 12-27-2019 at 10:22 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    02-16-2013
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: XLS to CSV with a Date on the filename - using VB

    Thank you very much.

    This is very close to what I needed and EXCELLENT!

    Is there some way to alter that to macro so that a date can be appended to the back of the filename. I have been doing a lot of different tests but seems no doable.

    This may just be outside the limits of what VB can do, but it's worth a shot.

    Thanks!

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: XLS to CSV with a Date on the filename - using VB

    Maybe:

                        ActiveWorkbook.SaveAs Filename:=fName & "-" & shCnt _
                            & Format(Date, "(MM-DD-YY)" & ".csv", FileFormat:=xlCSV, CreateBackup:=False

  5. #5
    Registered User
    Join Date
    02-16-2013
    Location
    Los Angeles, CA
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: XLS to CSV with a Date on the filename - using VB

    Thank you again.

    With a couple slight tweaks, I was able to get this rolling!

    Awesome!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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