#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Found Files

I have a folder with an ever expanding number of files named as follows

oldOrders001.xls
oldOrders002.xls
oldOrders003.xls
oldOrders004.xls
oldOrders005.xls
~
oldOrders095.xls

etc........

will the following piece of code always find the very last alphabetically
listed file, I only have win98 to test it on and am curious to know what
will happen on other platforms such as XP

With Application.FileSearch
.LookIn = "C:\shopmain\orders\done"
.SearchSubFolders = False
.FileName = "oldOrders*.xls"
.Execute
lastFile = .FoundFiles(.FoundFiles.Count)
End With





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Found Files

I don't think you can guarantee the sort order unless you specify it, but
that is not hard to do - this example is from the help file for FoundFiles:

Use the Execute method to begin the file search and update the FoundFiles
object. The following example searches the My Documents folder for all files
whose names begin with "Cmd" and displays the name and location of each file
that's found. The example also sorts the returned files in ascending
alphabetic order by file name.

Set fs = Application.FileSearch
With fs
.LookIn = "C:\My Documents"
.FileName = "cmd*"
If .Execute(SortBy:=msoSortbyFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With


"Stuart" wrote:

I have a folder with an ever expanding number of files named as follows

oldOrders001.xls
oldOrders002.xls
oldOrders003.xls
oldOrders004.xls
oldOrders005.xls
~
oldOrders095.xls

etc........

will the following piece of code always find the very last alphabetically
listed file, I only have win98 to test it on and am curious to know what
will happen on other platforms such as XP

With Application.FileSearch
.LookIn = "C:\shopmain\orders\done"
.SearchSubFolders = False
.FileName = "oldOrders*.xls"
.Execute
lastFile = .FoundFiles(.FoundFiles.Count)
End With






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Found Files

Brilliant, that's exactly what I wanted!


"K Dales" wrote in message
...
I don't think you can guarantee the sort order unless you specify it, but
that is not hard to do - this example is from the help file for

FoundFiles:

Use the Execute method to begin the file search and update the FoundFiles
object. The following example searches the My Documents folder for all

files
whose names begin with "Cmd" and displays the name and location of each

file
that's found. The example also sorts the returned files in ascending
alphabetic order by file name.

Set fs = Application.FileSearch
With fs
.LookIn = "C:\My Documents"
.FileName = "cmd*"
If .Execute(SortBy:=msoSortbyFileName, _
SortOrder:=msoSortOrderAscending) 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With


"Stuart" wrote:

I have a folder with an ever expanding number of files named as follows

oldOrders001.xls
oldOrders002.xls
oldOrders003.xls
oldOrders004.xls
oldOrders005.xls
~
oldOrders095.xls

etc........

will the following piece of code always find the very last

alphabetically
listed file, I only have win98 to test it on and am curious to know what
will happen on other platforms such as XP

With Application.FileSearch
.LookIn = "C:\shopmain\orders\done"
.SearchSubFolders = False
.FileName = "oldOrders*.xls"
.Execute
lastFile = .FoundFiles(.FoundFiles.Count)
End With








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
try to open excel files from explorer, 'file not found' JoM Excel Discussion (Misc queries) 2 January 24th 09 01:40 PM
Linking files "File Not Found" Dahlman Excel Discussion (Misc queries) 0 April 4th 05 08:31 PM
Filesearch : .zip files not found ??? Benoît HUBERT Excel Programming 1 September 1st 04 06:28 PM
Multiple personal.xls files found! aiyer[_40_] Excel Programming 2 August 16th 04 11:33 PM
Creating a list of found files Tom Ogilvy Excel Programming 1 October 1st 03 08:21 PM


All times are GMT +1. The time now is 04:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"