This has been an oustanding thread.
I am just learning VBA this morning as I am up against a similar challenge...pulling in multiple workbooks into on workbook. There is a piece I am trying to get at, but can't seem to figure out. Any help is really appreciated.
~
1. I want to pull in multiple workbooks (files) stored in same directory.
2. I want to have a few sheets in my 'Master Workbook File build charts and tables from the multiple workbooks.
3. I want the other workbooks to automatically update into the 'Master Workbook File' when I open the 'Master Workbook File'.
4. When I save the 'Master Workbook File', it saves all the imported worksheets ( ); however, if I want to update the file again later that day with new entered data in the individual workbooks, I have to rerun the Macro (goto Tools, etc..run Macro). This duplicates all the workbooks.
Basically, I want the imported workbooks to update automatically and copy over the previous "like" workbooks that were there at last saved point.
I have used the following code from above inporting my test case:
~~~
[VBA] Sub CombineFiles()
Dim Path As String
Dim FileName As String
Dim Wkb As Workbook
Dim WS As Worksheet
Dim Ch As Chart
ToggleStuff False
Path = "C:\Documents and Settings\Owner\My Documents"
With Application.FileSearch
.NewSearch
.LookIn = Path
.LastModified = msoLastModifiedAnyTime
.FileName = "LinkBook.xls"
If .Execute(msoSortByFileName, msoSortOrderDescending, True) > 0 Then
Workbooks.Open .FoundFiles(1), xlWindows
End If
End With
Set Wkb = ActiveWorkbook
For Each WS In Wkb.Worksheets
WS.Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Next WS
For Each Ch In Wkb.Charts
Ch.Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Next Ch
Wkb.Close False
ToggleStuff True
End Sub
Sub ToggleStuff(ByVal x As Boolean)
With Application
.EnableEvents = x
.ScreenUpdating = x
.DisplayAlerts = x
.AskToUpdateLinks = x
End With
End Sub[/VBA]
~~~