cmefly
Well-known Member
- Joined
- May 13, 2003
- Messages
- 683
hi,
I've got the following macro that goes into every excel file in a certain directory and copies certain cells to another worksheet...for some reason, it's not finding any files even though i clearly have 65 files in the directory...any help would be greatly appreciated.
Sub fetch2011columns()
Dim a, k As Integer
Dim strPath As String
Dim strFileName As String
Dim i As Integer
Dim vaFileName As Variant
strPath = "C:\2011"
a = 1
With Application.FileSearch
.LookIn = strPath
.Filename = ".xls"
For Each vaFileName In .FoundFiles
Workbooks.Open vaFileName
With ActiveWorkbook
.Worksheets("DataFetcher").Select
.Range("C5:C240, e5:e240,j5:j240,m5:m240").Select
.Close
End With
Windows("2011extractor").Activate
Range("A" & a).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
a = 240 * k + 1
Next
End With
End Sub
thanks,
Marc
I've got the following macro that goes into every excel file in a certain directory and copies certain cells to another worksheet...for some reason, it's not finding any files even though i clearly have 65 files in the directory...any help would be greatly appreciated.
Sub fetch2011columns()
Dim a, k As Integer
Dim strPath As String
Dim strFileName As String
Dim i As Integer
Dim vaFileName As Variant
strPath = "C:\2011"
a = 1
With Application.FileSearch
.LookIn = strPath
.Filename = ".xls"
For Each vaFileName In .FoundFiles
Workbooks.Open vaFileName
With ActiveWorkbook
.Worksheets("DataFetcher").Select
.Range("C5:C240, e5:e240,j5:j240,m5:m240").Select
.Close
End With
Windows("2011extractor").Activate
Range("A" & a).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
a = 240 * k + 1
Next
End With
End Sub
thanks,
Marc