+ Reply to Thread
Results 1 to 12 of 12

Combine workbooks

Hybrid View

  1. #1
    Registered User
    Join Date
    05-08-2010
    Location
    Classified
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Combine workbooks

    Wow, it works perfectly. You are incredible. Thank you so so much. I am reviewing the script now.

    Is there any way I can pay you back? Barring actual currency and/or sexual favors.

    :-)

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Combine workbooks

    A variation, just 'cuz it's a quiet Saturday:
    Sub CombineWorkbooks()
        Dim avsWkb      As Variant
        Dim vsWkb       As Variant
        Dim wks         As Worksheet
    
        On Error GoTo ErrHandler
        avsWkb = Application.GetOpenFilename(FileFilter:="Excel Files, *.xls", _
                                             MultiSelect:=True, _
                                             Title:="Files to Merge")
        If IsArray(avsWkb) Then
            Application.ScreenUpdating = False
    
            For Each vsWkb In avsWkb
                With Workbooks.Open(vsWkb)
    
                    For Each wks In .Worksheets
                        If WorksheetFunction.CountA(wks.UsedRange) Then
                            wks.Name = Left(.Name, InStrRev(.Name, ".") - 1) & " " & wks.Name
                            wks.Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
                        End If
                    Next wks
    
                    .Close SaveChanges:=False
                End With
            Next vsWkb
        Else
            MsgBox "No Files were selected"
        End If
    
    ExitHandler:
        Application.ScreenUpdating = True
        Exit Sub
    
    ErrHandler:
        MsgBox Err.Description
        Resume ExitHandler
    End Sub
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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