View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
Francesco
 
Posts: n/a
Default Please Help for a macro reading files not in sequence

Hello

I am using WindowsXP Prof. and Excel 2003
I the folders "invoice 2006" that are in the Drives A, C end E there are 6
each excel files numbered from _001_2006 to _006_2006.xls

The macro I wrote here down, reads the files in each folder and writes the
result in sheet1 starting in cell A1

It does it but they are not read in sequence appart those in C:\ that are
right, what I get is:

A:\_002_2006.xls
A:\_001_2006.xls
A:\_003_2006.xls
A:\_004_2006.xls
A:\_005_2006.xls
A:\_006_2006.xls

C:\_001_2006.xls
C:\_002_2006.xls
C:\_003_2006.xls
C:\_004_2006.xls
C:\_005_2006.xls
C:\_006_2006.xls

E:\_006_2006.xls
E:\_001_2006.xls
E:\_002_2006.xls
E:\_003_2006.xls
E:\_004_2006.xls
E:\_005_2006.xls

Moreover if it is possible I would like to comapre the files in the
mentioned folder and if in one of them one or more files are missing in one
of the folder the macro should copy them in it.

What is wrong in the nacro?
Thanks for any help I can get on the matter
Francesco


Sub ListFiles()
Dim aryDrives
Dim oFSO
Dim n As Long
Dim i As Long


Dim sPath As String
On Error GoTo cleanUp
On Error Resume Next
aryDrives = Array("A:\", "C:\", "E:\")
Set oFSO = CreateObject("Scripting.FileSystemObject")
i = 0 'Set i to row-1 of the starting row of the data.

For n = LBound(aryDrives) To UBound(aryDrives)
sPath = aryDrives(n)
MyPath = sPath & "invoicingPRG\Invoice2006\*.*"
'MyPath = "C:\programmaFatturazione\Fatture2006\*.*" 'Modify
to suit

myFile = Dir(MyPath, vbNormal)
While myFile < ""

Cells(i, 1) = sPath & myFile 'Modify 1 here to the column you want
the List
myFile = Dir
i = i + 1
Wend
i = i + 1
Next n
cleanUp:
Application.ScreenUpdating = True
End Sub