I have the code below set up in a macro I used a few years back and am trying to use again in excel 2007. It seems to be getting hung up on the following line:
Set FS = Application.FileSearch
The purpose of the workbook is to find all excel files in the same folder as this workbook, open, copy information, paste it in the "master document", and close each one at a time.
Your help is appreciated!
Private Sub cmdUpdate_Click()
Dim FS, i
Dim PlaceRow As Long
Dim OpenedName As String
Dim DoNotReopenActiveWB_Name As String
Dim DataBook As String
Sheet1.Range("A2:AF1000").ClearContents
Sheet1.Range("BA1:BA1000").ClearContents
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False
DoNotReopenActiveWB_Name = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name
DataBook = ActiveWorkbook.Name
PlaceRow = 1
Debug.Print DoNotReopenActiveWB_Name
Set FS = Application.FileSearch
With FS
.LookIn = ActiveWorkbook.Path
.Filename = "*.XLS"
If .Execute Then
For i = 1 To .FoundFiles.Count
If .FoundFiles(i) <> DoNotReopenActiveWB_Name Then
PlaceRow = PlaceRow + 1
Workbooks.Open .FoundFiles(i)
OpenedName = ActiveWorkbook.Name
Workbooks(DataBook).Sheets("Table1") _
.Range("A" & PlaceRow & ":AF" & PlaceRow).Value = _
Workbooks(OpenedName).Sheets("Sheet1") _
.Range("A114:AF114").Value
Workbooks(DataBook).Sheets("Table1") _
.Range("BA" & PlaceRow).Value = .FoundFiles(i)
Workbooks(OpenedName).Close savechanges:=False
End If
Next i
End If
End With
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Set FS = Application.FileSearch
The purpose of the workbook is to find all excel files in the same folder as this workbook, open, copy information, paste it in the "master document", and close each one at a time.
Your help is appreciated!
Private Sub cmdUpdate_Click()
Dim FS, i
Dim PlaceRow As Long
Dim OpenedName As String
Dim DoNotReopenActiveWB_Name As String
Dim DataBook As String
Sheet1.Range("A2:AF1000").ClearContents
Sheet1.Range("BA1:BA1000").ClearContents
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False
DoNotReopenActiveWB_Name = ActiveWorkbook.Path & "\" & ActiveWorkbook.Name
DataBook = ActiveWorkbook.Name
PlaceRow = 1
Debug.Print DoNotReopenActiveWB_Name
Set FS = Application.FileSearch
With FS
.LookIn = ActiveWorkbook.Path
.Filename = "*.XLS"
If .Execute Then
For i = 1 To .FoundFiles.Count
If .FoundFiles(i) <> DoNotReopenActiveWB_Name Then
PlaceRow = PlaceRow + 1
Workbooks.Open .FoundFiles(i)
OpenedName = ActiveWorkbook.Name
Workbooks(DataBook).Sheets("Table1") _
.Range("A" & PlaceRow & ":AF" & PlaceRow).Value = _
Workbooks(OpenedName).Sheets("Sheet1") _
.Range("A114:AF114").Value
Workbooks(DataBook).Sheets("Table1") _
.Range("BA" & PlaceRow).Value = .FoundFiles(i)
Workbooks(OpenedName).Close savechanges:=False
End If
Next i
End If
End With
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub