Hi,
I had the following code working in Excel 2003 to read a hidden tab (SummaryMirror) with data and copy the data into one new workbook for all files within a specific directory.
Sub MergeTrackers()
Dim lastRow As Integer
Dim docPath As String
Dim baseCell As Excel.Range
Dim sysObj As Variant, folderObj As Variant, fileObj As Variant
Application.ScreenUpdating = False
docPath = Application.GetOpenFilename(FileFilter:="Text Files (*.txt),*.txt,Excel Files (*.xls),*.xls,Excel 2007 Files (*.xlsx),*.xlsx", FilterIndex:=2, Title:="Choose any file")
Workbooks.Add
Set baseCell = Range("A1")
Set sysObj = CreateObject("scripting.filesystemobject")
Set fileObj = sysObj.getFile(docPath)
Set folderObj = fileObj.ParentFolder
Application.DisplayAlerts = False
For Each fileObj In folderObj.Files
Workbooks.Open Filename:=fileObj.Path
Sheets("SummaryMirror").Visible = True
Sheets("SummaryMirror").Unprotect Password:="password"
Sheets("SummaryMirror").Select
Range(Range("A1:N12"), ActiveCell.SpecialCells(xlLastCell)).Copy
lastRow = baseCell.SpecialCells(xlLastCell).Row
baseCell.Offset(lastRow, 0).PasteSpecial (xlPasteValues)
baseCell.Copy
ActiveWindow.Close SaveChanges:=False
Next
End Sub
I upgraded to Excel 2007 and now the code does not work anymore... Does anyone know how to solve for Excel 2007?
Many thanks!
I had the following code working in Excel 2003 to read a hidden tab (SummaryMirror) with data and copy the data into one new workbook for all files within a specific directory.
Sub MergeTrackers()
Dim lastRow As Integer
Dim docPath As String
Dim baseCell As Excel.Range
Dim sysObj As Variant, folderObj As Variant, fileObj As Variant
Application.ScreenUpdating = False
docPath = Application.GetOpenFilename(FileFilter:="Text Files (*.txt),*.txt,Excel Files (*.xls),*.xls,Excel 2007 Files (*.xlsx),*.xlsx", FilterIndex:=2, Title:="Choose any file")
Workbooks.Add
Set baseCell = Range("A1")
Set sysObj = CreateObject("scripting.filesystemobject")
Set fileObj = sysObj.getFile(docPath)
Set folderObj = fileObj.ParentFolder
Application.DisplayAlerts = False
For Each fileObj In folderObj.Files
Workbooks.Open Filename:=fileObj.Path
Sheets("SummaryMirror").Visible = True
Sheets("SummaryMirror").Unprotect Password:="password"
Sheets("SummaryMirror").Select
Range(Range("A1:N12"), ActiveCell.SpecialCells(xlLastCell)).Copy
lastRow = baseCell.SpecialCells(xlLastCell).Row
baseCell.Offset(lastRow, 0).PasteSpecial (xlPasteValues)
baseCell.Copy
ActiveWindow.Close SaveChanges:=False
Next
End Sub
I upgraded to Excel 2007 and now the code does not work anymore... Does anyone know how to solve for Excel 2007?
Many thanks!