Managing files in macro built for Xls 2000 not working in 2007 just a tip needed

metatron

New Member
Joined
Aug 24, 2015
Messages
2
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!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Upvote 0

Forum statistics

Threads
1,215,356
Messages
6,124,475
Members
449,164
Latest member
Monchichi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top