Thursday, January 17, 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

Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose, we have a sample Sales data, which is stored with Monthly Snaps...

Popular Posts from this Blog