Thursday, 17 January 2013

How to Create a Dialog Box To Select and Merge Multiple Workbooks into Main Workbook

Excel VBA Macro to Open Dialog Box To Select and Merge Multiple Workbooks into Target Workbook
'This is Very User Friendly Macro that allows you to Merge Multiple Workbooks Selected from a open Dialog Box Into Our Workbook'

Sub CombineWorkbooks()

    Dim FilesToOpen As Variant
    Dim X As Integer

    On Error GoTo ErrHandler

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    FilesToOpen = Application.GetOpenFilename
 (FileFilter:="Microsoft Excel Files (*.xls*), *.xls*",MultiSelect:=True, Title:="Files to Merge")

    If TypeName(FilesToOpen) = "Boolean" Then

        MsgBox "No Files Were Selected"
        GoTo ExitHandler
    End If

   X = 1

    While X <= UBound(FilesToOpen)
        Workbooks.Open Filename:=FilesToOpen(x)
        Sheets().Move After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
        + 1
    Wend
    
ExitHandler:
    Application.ScreenUpdating = True
    Exit Sub

ErrHandler:

    MsgBox Err.Description, vbCritical, "Error"
    Resume ExitHandler
End Sub

Thanks,
Tamatam
  

No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts