+ Reply to Thread
Results 1 to 8 of 8

VBA Export to CSV with Specified File Name

  1. #1
    Registered User
    Join Date
    04-09-2015
    Location
    Manchester, England
    MS-Off Ver
    2010
    Posts
    39

    VBA Export to CSV with Specified File Name

    Hi All,

    I'm looking for VBA code that will export the current worksheet to a CSV file, save it in a pre-determind file path, but allow the user to enter a custom file name.

    The code that I'm currently using (below), works completely fine for exporting and saving in the correct path, but the user is unable to specify a file name. Any ideas?

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA Export to CSV with Specified File Name

    Hi,

    One way would be to prompt the user for the name with a VBA Input box.

    e.g.

    Please Login or Register  to view this content.

    alternatively have the user record the file name in a cell and use that. i.e.

    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    04-09-2015
    Location
    Manchester, England
    MS-Off Ver
    2010
    Posts
    39

    Re: VBA Export to CSV with Specified File Name

    Thanks a lot richard, that worked perfectly!

    One more thing, if you've got a spare minute. The sheet I'm exporting is a Pivot Table, so lines 1 through 8 are blank or filters. Is there a way I can export only the data from A9 to the end of my data?

    Thanks for your help,
    Dom

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA Export to CSV with Specified File Name

    Hi Dom,

    Immediately after

    Please Login or Register  to view this content.
    put
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    04-09-2015
    Location
    Manchester, England
    MS-Off Ver
    2010
    Posts
    39

    Re: VBA Export to CSV with Specified File Name

    Hi Richard,

    Thanks for the quick response. Unfortunately, as the base spreadsheet is a Pivot Table, it's preventing me from deleting the first 8 rows. I'm receiving the below error message when running the macro.

    Is there a way to bypass this error and delete them anyway?

    Error.PNG

    Thanks,
    Dom

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA Export to CSV with Specified File Name

    In that case the only simple way I can think of is to copy the Pivot table and paste it as a range then delete the columns containing the pivot table. Something like


    Please Login or Register  to view this content.
    Change the pivot table name as appropriate and change "M1" to the first unused column

  7. #7
    Registered User
    Join Date
    04-09-2015
    Location
    Manchester, England
    MS-Off Ver
    2010
    Posts
    39

    Re: VBA Export to CSV with Specified File Name

    Hi Richard,

    Worked like a charm. Had to edit slightly, pasted the values in to A1 and removed the line about deleting columns A:L. See complete working code below. Thank you for all of your help.

    Please Login or Register  to view this content.
    Kind regards,
    Dom

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: VBA Export to CSV with Specified File Name

    Glad to have helped and thanks for the rep.

+ 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. Export Cells to Text and automatically have File Name and File Type Selected
    By bloomingcarrot in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-18-2014, 03:37 PM
  2. [SOLVED] Trying to export a report to .XML file but no data being included in the file
    By steveallany2k6 in forum Access Tables & Databases
    Replies: 2
    Last Post: 04-18-2013, 07:16 AM
  3. Export To Inf file & Zip the Files from the given file paths picking every 10 rows
    By vivekhalder in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2012, 03:59 AM
  4. Export Excel records to seperate text file & compress it to protecte ZIP file
    By firedragon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-03-2012, 10:47 AM
  5. Export excel file to semicolon delimited text file
    By capitan in forum Excel General
    Replies: 5
    Last Post: 04-06-2005, 11:07 PM
  6. Export excel file to semicolon delimited text file
    By capitan in forum Excel General
    Replies: 5
    Last Post: 04-06-2005, 11:07 PM
  7. How do I import text file, analyze data, export results, open next file
    By Geoffro in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-06-2005, 04:06 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