Would really appreciate your help.
I have this macro built on excel 2000 which has to be updated for 2007 and doesnt work.
Basically I have to collect information from 1000 other excell files and place it in one workshhet.
Sub lucas()
Range("A1").Select
Dim FS
Dim fichero
Dim i
Dim dato1
Set FS = Application.FileSearch
With FS
.LookIn = "F:\planes"
.FileName = "*.xls"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
' MsgBox "Se encontraron " & .FoundFiles.Count & " archivo(s)."
Dim AÑO As Integer
AÑO = InputBox("Por favor, indique el año para el que desea totales.", "Calculo de Totales")
Worksheets(1).Range("a2:k10000").ClearContents
For i = 1 To .FoundFiles.Count
ActiveCell.Offset(i, 0) = .FoundFiles(i)
fichero = .FoundFiles(i)
Workbooks.Open (fichero)
Dim datos As Integer
dato1 = WorksheetFunction.VLookup(AÑO, Worksheets(1).Range("a5:u100"), 1, False)
ActiveWorkbook.Close
ActiveCell.Offset(i, 1) = dato1
Next i
SearchOrder:=xlByColumns, MatchCase:=True
Else
MsgBox "No se encontró ningún archivo."
End If
End With
Noticed that some commands have changed in this version, and have been able to make an initial change searching for files with:
' Find and count files
StrPath = "F:\PLANES\"
strFile = Dir(StrPath & "*.XLS")
Do While strFile <> ""
i = i + 1
Debug.Print strFile
strFile = Dir
Loop
MsgBox "Total files found: " & i
But reaching to the For i = 1 To .FoundFiles.Count I get an error and cant find the solution to work with each file.
Obviously Im not an epert.
Many thanks in advance!
I have this macro built on excel 2000 which has to be updated for 2007 and doesnt work.
Basically I have to collect information from 1000 other excell files and place it in one workshhet.
Sub lucas()
Range("A1").Select
Dim FS
Dim fichero
Dim i
Dim dato1
Set FS = Application.FileSearch
With FS
.LookIn = "F:\planes"
.FileName = "*.xls"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
' MsgBox "Se encontraron " & .FoundFiles.Count & " archivo(s)."
Dim AÑO As Integer
AÑO = InputBox("Por favor, indique el año para el que desea totales.", "Calculo de Totales")
Worksheets(1).Range("a2:k10000").ClearContents
For i = 1 To .FoundFiles.Count
ActiveCell.Offset(i, 0) = .FoundFiles(i)
fichero = .FoundFiles(i)
Workbooks.Open (fichero)
Dim datos As Integer
dato1 = WorksheetFunction.VLookup(AÑO, Worksheets(1).Range("a5:u100"), 1, False)
ActiveWorkbook.Close
ActiveCell.Offset(i, 1) = dato1
Next i
SearchOrder:=xlByColumns, MatchCase:=True
Else
MsgBox "No se encontró ningún archivo."
End If
End With
Noticed that some commands have changed in this version, and have been able to make an initial change searching for files with:
' Find and count files
StrPath = "F:\PLANES\"
strFile = Dir(StrPath & "*.XLS")
Do While strFile <> ""
i = i + 1
Debug.Print strFile
strFile = Dir
Loop
MsgBox "Total files found: " & i
But reaching to the For i = 1 To .FoundFiles.Count I get an error and cant find the solution to work with each file.
Obviously Im not an epert.
Many thanks in advance!