ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to pick the right file (https://www.excelbanter.com/excel-programming/356073-how-pick-right-file.html)

Ben

How to pick the right file
 
Hi all,

I have a series of Excel files in a directory out in the network. The file
names are suffixed by a date stamp as in: "_mm-dd-yyy.xls". I need to open
the latest file. But the latest file can be older than the date in the
system's clock. For example, it can be Monday today and the latest file is
from previous week's Friday. I was thinking of using a array or file system
object to read in all the files and truncate the date portion and compare
them. But that seems me a very ineffective and inefficient way of doing
thing. Can you share your thoughts or code snipppets? Thanks.

Ben

--

--


Tom Ogilvy

How to pick the right file
 
If it will always be withing a couple of days

Dim dt as Date
dt = Date
do while dir("C:\Myfolder\*_" & format(dt,"mm-dd-yyyy.xls") = ""
dt = dt - 1
if dt < Date - 5 then
msgbox "Problems"
exit sub
end if
Loop
--
Regards,
Tom Ogilvy




"Ben" wrote:

Hi all,

I have a series of Excel files in a directory out in the network. The file
names are suffixed by a date stamp as in: "_mm-dd-yyy.xls". I need to open
the latest file. But the latest file can be older than the date in the
system's clock. For example, it can be Monday today and the latest file is
from previous week's Friday. I was thinking of using a array or file system
object to read in all the files and truncate the date portion and compare
them. But that seems me a very ineffective and inefficient way of doing
thing. Can you share your thoughts or code snipppets? Thanks.

Ben

--

--



All times are GMT +1. The time now is 10:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com