I think I misunderstood your question. You weren't asking why the
activeworkbook hides the inactive workbooks. You want to open some workbooks,
copy some cells/rows into a giant consolidated worksheet.
This kind of code depends on a lot of things--where the workbooks are located
(drive/folder), what worksheets (the first/only in the workbook or all or just
some).
I assumed that your files are all in the same folder. You'll get a File|open
dialog. Click on the first workbook and ctrl-click on subsequent workbooks.
This routine copies the data from first worksheet in each of the selected
workbooks into a new worksheet in a new workbook.
Sub testme()
Dim newWks As Worksheet
Dim myFileNames As Variant
Dim nextWkbk As Workbook
Dim wks As Worksheet
Dim fCtr As Long
Dim DestCell As Range
Dim RngToCopy As Range
myFileNames = Application.GetOpenFilename _
(FileFilter:="Excel files, *.xls", _
MultiSelect:=True)
If IsArray(myFileNames) Then
Application.ScreenUpdating = False
Set newWks = Workbooks.Add(1).Worksheets(1)
Set DestCell = newWks.Range("a1")
For fCtr = LBound(myFileNames) To UBound(myFileNames)
Set nextWkbk = Nothing
On Error Resume Next
Set nextWkbk = Workbooks.Open(Filename:=myFileNames(fCtr))
On Error GoTo 0
If nextWkbk Is Nothing Then
MsgBox "Error with: " & myFileNames(fCtr)
Else
With nextWkbk.Worksheets(1)
Set RngToCopy = .Range("a1", _
.Cells.SpecialCells(xlCellTypeLastCell))
End With
RngToCopy.Copy _
Destination:=DestCell
Set DestCell = newWks.Cells.SpecialCells(xlCellTypeLastCell) _
.EntireRow.Cells(1).Offset(1, 0)
nextWkbk.Close savechanges:=False
End If
Next fCtr
Else
MsgBox "try again later!"
End If
Application.ScreenUpdating = True
End Sub
If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
Thank you Dave and tghcogo,
I really want these files on the same sheet. I have several files about
3,000 rows each and want them to run consequtively on the same sheet. One
worksheet in a single workbook. Any solutions?
littlebit