+ Reply to Thread
Results 1 to 5 of 5

Export multiple (specific) range names to CSV files in a specified directory

  1. #1
    Registered User
    Join Date
    03-21-2013
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    3

    Export multiple (specific) range names to CSV files in a specified directory

    Hi there,

    I'm new to VBA and am struggling to convert the following working script from exporting tabs that contain a specified key word to export similar range names instead:

    Sub CreateCSV()
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    '-----------------------------
    'DECLARE AND SET VARIABLES
    Dim wb1 As Workbook, ws1 As Worksheet
    Dim wbname As String, I As Integer
    Set wb1 = ThisWorkbook
    '-----------------------------
    'CYCLE THROUGH SHEETS AND MATCH UPLOAD
    For I = 1 To Worksheets.Count
    wbname = Worksheets(I).Name
    If InStr(1, Ucase(Worksheets(I).Name), "UPLOAD", vbTextCompare) > 0 Then
    '-----------------------------
    'COPY SHEET INTO NEW CSV FILE
    Worksheets(I).Copy
    ActiveWorkbook.SaveAs Filename:="C:\Users\Maudibe\Documents\" & wbname & ".csv", _
    FileFormat:=xlCSV, CreateBackup:=False
    ActiveWorkbook.Close
    wb1.Activate
    End If
    Next I
    '-----------------------------
    'CLEANUP
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub

    Any pointers gratefully received.

    Thanks,
    John

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Export multiple (specific) range names to CSV files in a specified directory

    from exporting tabs that contain a specified key word to export similar range names instead
    Can you clarify this?
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    03-21-2013
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Export multiple (specific) range names to CSV files in a specified directory

    Hi there,

    Basically the above script works great in that it creates CSV files from any tabs that contain "UPLOAD" in their name into the defined folder.

    The problem is that said tabs and hence said CSV files have two additional rows at the top which I need to get rid of during this export so that another system can import the files I but can't work out how to do that and am not sure that's possible?

    I was thinking then that another way to approach this would be to attempt to create the CSV files from range names instead but that could be flawed thinking?

    Appreciate your time.

    Thanks,
    John

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Export multiple (specific) range names to CSV files in a specified directory

    I still don't get the connection between the sheet name and removing the data from the sheet. If you want to remove two rows of data from each sheet, just insert this before the Worksheets(I).Copy statement
    Please Login or Register  to view this content.
    and then modify this line as shown

    Please Login or Register  to view this content.
    Which will allow your original file to remain intact.

  5. #5
    Registered User
    Join Date
    03-21-2013
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Export multiple (specific) range names to CSV files in a specified directory

    Sorry, took a while to get back to this. Thanks for the pointer and with a bit of help from google I'm sorted.

    Cheers,
    John

+ 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. [SOLVED] macro to copy excel files only from main directory and sub directory to a specific folder
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-05-2019, 09:49 AM
  2. [SOLVED] Export multiple (specific) worksheets to CSV files in a specified directory
    By reghyh in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-25-2015, 02:43 AM
  3. Listing Names of Files in Directory to Excel Worksheet
    By Branchard in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-02-2014, 06:31 AM
  4. [SOLVED] Importing specific data from multiple text files in a file directory into excel
    By abat in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 07-03-2013, 05:26 PM
  5. [SOLVED] Copy specific files from one directory to another
    By brazil in forum Excel General
    Replies: 2
    Last Post: 03-06-2013, 03:56 PM
  6. [SOLVED] Reading in files from directory......does this code also alphabetize the file names
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-24-2012, 08:20 AM
  7. Opening files in specific directory
    By randell.graybill in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-28-2009, 12:34 AM

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