Hello, Thank You for giving me your precious time.
I have following code to open new files through dialog box and add all sheets from them into current workbook. It is working fine as a macro but when I save it as Add-In and select multiple workbooks to open, it opens only sheets from one workbook.
Sub opensheets()
Dim openfiles
Dim crntfile As Workbook
Set crntfile = ActiveWorkbook
Dim x As Integer
On Error GoTo ErrHandler
Application.ScreenUpdating = False
openfiles = Application.GetOpenFilename _
(FileFilter:="Microsoft Excel Files (*.xls;*.xlsx),*.xls;*.xlsx", _
MultiSelect:=True, Title:="Select Excel files!")
If TypeName(openfiles) = "Boolean" Then
MsgBox "You need to select atleast one file"
GoTo ExitHandler
End If
x = 1
While x <= UBound(openfiles)
Workbooks.Open Filename:=openfiles(x)
Sheets().Move After:=crntfile.Sheets(crntfile.Sheets.Count)
x = x + 1
Wend
ExitHandler:
Application.ScreenUpdating = True
Exit Sub
ErrHandler:
MsgBox Err.Description
Resume ExitHandler
End Sub
I have following code to open new files through dialog box and add all sheets from them into current workbook. It is working fine as a macro but when I save it as Add-In and select multiple workbooks to open, it opens only sheets from one workbook.
Sub opensheets()
Dim openfiles
Dim crntfile As Workbook
Set crntfile = ActiveWorkbook
Dim x As Integer
On Error GoTo ErrHandler
Application.ScreenUpdating = False
openfiles = Application.GetOpenFilename _
(FileFilter:="Microsoft Excel Files (*.xls;*.xlsx),*.xls;*.xlsx", _
MultiSelect:=True, Title:="Select Excel files!")
If TypeName(openfiles) = "Boolean" Then
MsgBox "You need to select atleast one file"
GoTo ExitHandler
End If
x = 1
While x <= UBound(openfiles)
Workbooks.Open Filename:=openfiles(x)
Sheets().Move After:=crntfile.Sheets(crntfile.Sheets.Count)
x = x + 1
Wend
ExitHandler:
Application.ScreenUpdating = True
Exit Sub
ErrHandler:
MsgBox Err.Description
Resume ExitHandler
End Sub