+ Reply to Thread
Results 1 to 4 of 4

Saving multiple selected worksheets from a listbox as separate excel files

Hybrid View

  1. #1
    Registered User
    Join Date
    03-24-2013
    Location
    Quezon City, Philippines
    MS-Off Ver
    Excel 2010/2013
    Posts
    83

    Saving multiple selected worksheets from a listbox as separate excel files

    Hi all,

    I found a code where in when selecting multiple worksheets in a listbox it will be saved as multiple pdf files. What I want to happen is that instead of saving it as pdf, it will be saved as multiple excel files and I want to save it depending on the path I put in Cell J5.

    For example, I have a listbox containing Sheet1, Sheet2, Sheet3, Sheet4 and Sheet5.
    If I select Sheet1 and Sheet2, the output will be 2 separated excel files containing their data.

    The code that I found here: http://www.mrexcel.com/forum/excel-q...stbox-pdf.html is for saving multiple selected worksheets from a listbox as pdf.

    Here's the code:

    
    Dim arrSheets()
    Dim relativePath As String
    Dim idx As Long    ' don't use Selected, that's a listbox property.:)
    Dim cnt As Long
    
        For idx = 0 To ListBox1.ListCount - 1
            If ListBox1.Selected(idx) Then
                ReDim Preserve arrSheets(cnt)
                arrSheets(cnt) = ListBox1.List(idx)
                cnt = cnt + 1
            End If
        Next idx
    
        If cnt > 0 Then
            relativePath = "C:\TEST\" & Sheets("Title").Range("B28").Value
            Sheets(arrSheets).Select
            ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=relativePath
        End If
    Thank you!

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: Saving multiple selected worksheets from a listbox as separate excel files

    Sub tst()
    Dim relativePath As String
    Dim idx As Long    ' don't use Selected, that's a listbox property.:)
    
        For idx = 0 To ListBox1.ListCount - 1
            If ListBox1.Selected(idx) Then
                relativePath = "C:\TEST\" & ListBox1.Selected(idx) 'change to need
                Sheets(ListBox1.List(idx)).Copy
                With ActiveWorkbook
                    .SaveAs relativePath, 51
                    .Close True
                End With
            End If
        Next
        
    End Sub

  3. #3
    Registered User
    Join Date
    03-24-2013
    Location
    Quezon City, Philippines
    MS-Off Ver
    Excel 2010/2013
    Posts
    83

    Re: Saving multiple selected worksheets from a listbox as separate excel files

    Quote Originally Posted by bakerman2 View Post
    Sub tst()
    
                relativePath = "C:\TEST\" & ListBox1.Selected(idx) 'change to need
    
    End Sub
    Hi bakerman2,

    Just wondering, how can I change the relativepath? What if I want to select a folder first then save it?

    Thank you for the quick reply! Will test your code.

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,913

    Re: Saving multiple selected worksheets from a listbox as separate excel files

        With Application.FileDialog(msoFileDialogFolderPicker)
            .AllowMultiSelect = False
                If .Show <> -1 Then MsgBox "No folder selected! Exiting sub...": Exit Sub
                mydir = .SelectedItems(1)
        End With
        relativePath = mydir & "\" & ListBox1.Selected(idx) 'change to need

+ 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. Combine multiple files in one, under separate worksheets
    By plans in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-29-2014, 04:04 AM
  2. Separate several worksheets into excel files
    By mnp101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-09-2013, 11:13 PM
  3. [SOLVED] VBA to save multiple worksheets as separate CSV files using name of worksheet
    By Yg74 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-20-2012, 10:55 AM
  4. VBA to save multiple worksheets as separate CSV files using name of worksheet
    By titushanke in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-20-2012, 08:08 AM
  5. Replies: 1
    Last Post: 02-29-2012, 01:15 PM
  6. Print multiple selected worksheets to separate PDF's
    By Samantha McNeill in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-11-2010, 07:38 PM
  7. [SOLVED] Saving each row of an excel file in separate excel files
    By acamci in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-18-2006, 05:10 AM

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