View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default Open multiple workbook then combine into single workbook but different sheets

See code below.

HTH,
Bernie
MS Excel MVP


Sub MergeUserSelectedFiles()
Dim FileArray As Variant
Dim myB As Workbook
Dim myNB As Workbook
Dim i As Integer

Set myNB = Workbooks.Add

FileArray = Application.GetOpenFilename(MultiSelect:=True)
If IsArray(FileArray) Then
For i = LBound(FileArray) To UBound(FileArray)
Set myB = Workbooks.Open(FileArray(i))
myB.Worksheets.Copy befo=myNB.Worksheets(1)
myB.Close False
Next i
Else:
MsgBox "You clicked cancel"
End If
End Sub



"geniusideas" wrote in message
...
On Nov 24, 10:34 pm, "Bernie Deitrick" <deitbe @ consumer dot org
wrote:
Use a macro - run the code below, and select the files of interest in the
dialog.

HTH,
Bernie
MS Excel MVP

Sub MergeUserSelectedFiles()
Dim FileArray As Variant
Dim myB As Workbook
Dim i As Integer

FileArray = Application.GetOpenFilename(MultiSelect:=True)
If IsArray(FileArray) Then
For i = LBound(FileArray) To UBound(FileArray)
Set myB = Workbooks.Open(FileArray(i))
myB.Worksheets.Copy befo=ThisWorkbook.Worksheets(1)
myB.Close False
Next i
Else:
MsgBox "You clicked cancel"
End If
End Sub

"geniusideas" wrote in message

...

Hi!
The task now is to Open multiple workbook then combine into single
workbook but different sheets.
Pls help how to do in vba?


Thanks


Thanks bernie..

It's work. if I want to combined into new workbook how to do because
currently if I run it will combined into current workbook. Pls
help .Thank