2008-05-16, 18:35 #1
- Join Date
- Sep 2001
- Stuck at work..., Missouri, USA
- Thanked 0 Times in 0 Posts
Processing order of importing files (2003)
I have the following code that gets a list of files to import. <pre>FName = Dir(importPath & "PO*.csv")
Do While FName <> ""
ImportData = True
FileList(i) = FName
'move to the next file in the list
FName = Dir
i = i + 1
TotFiles = i</pre>
Then that array is run through and the files are imported into my database.
Is it possible to control the order they are loaded to the array? I NEED to process the oldest file first.
Thanks!<font face="Comic Sans MS">Morgan Erickson</font face=comic>
<img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18>-From <img src=/S/flags/Colorado.gif border=0 alt=Colorado width=30 height=18> but living in <img src=/S/flags/Missouri.gif border=0 alt=Missouri width=30 height=18>...and working in Kansas.
Subscribe to our Windows Secrets Newsletter - It's Free!
Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!
+ Get this BONUS — free!
Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!
2008-05-16, 20:02 #2
- Join Date
- Mar 2002
- Thanked 16 Times in 16 Posts
Re: Processing order of importing files (2003)
Dir always loops through the files in alphabetic order. You cannot change that. You could use Application.FileSearch instead. It results in an array of filenames, so you don't have to create the array yourself. And you can also get the number of found files
Dim i As Integer
.LookIn = importPath
.Filename = "PO*.csv"
If .Execute(msoSortByLastModified, msoSortOrderAscending) > 0 Then
TotFiles = .FoundFiles.Count
For i = 1 To TotFiles
Note: the FoundFiles array contains the complete file names including the path, not just the file names.
Warning: FileSearch is not available in Office 2007 any more.