Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Get the most recent file from a directory

I'm writing a VBA macro that compares data between the currently open
worksheet and the one produced the previous week. Right now the user has
to manually open the previous worksheet, but I thought it would be nifty
if I automatically open it.

So my question is, given a target folder cLocation and a pattern
"foo*.xls", how can I get the name of the most recent (prior to today)
matching file in that location?

--
Peter B. Steiger
Cheyenne, WY
If you must reply by email, you can reach me by placing zeroes
where you see stars: wypbs.**1 at gmail.com.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Get the most recent file from a directory

It's hard to go wrong with John Walkenbach...
http://www.j-walk.com/ss/excel/tips/tip97.htm
-or-
My own VBA code, using the FileSystemObject, allows one to specify
the number of most recent files to return.
I'll post the code upon request.
--
Jim Cone
Portland, Oregon USA



"Peter B. Steiger"
wrote in message
I'm writing a VBA macro that compares data between the currently open
worksheet and the one produced the previous week. Right now the user has
to manually open the previous worksheet, but I thought it would be nifty
if I automatically open it.
So my question is, given a target folder cLocation and a pattern
"foo*.xls", how can I get the name of the most recent (prior to today)
matching file in that location?

--
Peter B. Steiger
Cheyenne, WY
If you must reply by email, you can reach me by placing zeroes
where you see stars: wypbs.**1 at gmail.com.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Get the most recent file from a directory

The reason I asked if the date was encoded in the filename is my fear that a
wrong file could be returned using the code cited. IF a user were to modify
an older file in the directory for some reason, then that file would have a
later "modified date" than the true last created file. There is an API
solution that can look as the actual creation date for the file, but if the
date is encoded in the file names, that would be a much easier solution.

--
Rick (MVP - Excel)


"Jim Cone" wrote in message
...
It's hard to go wrong with John Walkenbach...
http://www.j-walk.com/ss/excel/tips/tip97.htm
-or-
My own VBA code, using the FileSystemObject, allows one to specify
the number of most recent files to return.
I'll post the code upon request.
--
Jim Cone
Portland, Oregon USA



"Peter B. Steiger"
wrote in message
I'm writing a VBA macro that compares data between the currently open
worksheet and the one produced the previous week. Right now the user has
to manually open the previous worksheet, but I thought it would be nifty
if I automatically open it.
So my question is, given a target folder cLocation and a pattern
"foo*.xls", how can I get the name of the most recent (prior to today)
matching file in that location?

--
Peter B. Steiger
Cheyenne, WY
If you must reply by email, you can reach me by placing zeroes
where you see stars: wypbs.**1 at gmail.com.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Get the most recent file from a directory

Rick,
Thanks for that info. I have never paid any attention to file creation date
vs. last modified date and have always just used a last modified date.

I checked the help file for the Scripting Runtime library and found that the
File object does have both a DateCreated and a DateLastModified property.
I ran a my FSO code and the DateCreated files returned are different
(and earlier dated) then the DateLastModified files.

Maybe another optional argument for the function.
--
Jim Cone
Portland, Oregon USA
(don't look back, they might be gaining on you)




"Rick Rothstein"
wrote in message
The reason I asked if the date was encoded in the filename is my fear that a
wrong file could be returned using the code cited. IF a user were to modify
an older file in the directory for some reason, then that file would have a
later "modified date" than the true last created file. There is an API
solution that can look as the actual creation date for the file, but if the
date is encoded in the file names, that would be a much easier solution.
--
Rick (MVP - Excel)


"Jim Cone" wrote in message
...
It's hard to go wrong with John Walkenbach...
http://www.j-walk.com/ss/excel/tips/tip97.htm
-or-
My own VBA code, using the FileSystemObject, allows one to specify
the number of most recent files to return.
I'll post the code upon request.
--
Jim Cone
Portland, Oregon USA



"Peter B. Steiger"
wrote in message
I'm writing a VBA macro that compares data between the currently open
worksheet and the one produced the previous week. Right now the user has
to manually open the previous worksheet, but I thought it would be nifty
if I automatically open it.
So my question is, given a target folder cLocation and a pattern
"foo*.xls", how can I get the name of the most recent (prior to today)
matching file in that location?

--
Peter B. Steiger
Cheyenne, WY
If you must reply by email, you can reach me by placing zeroes
where you see stars: wypbs.**1 at gmail.com.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Get the most recent file from a directory

On Thu, 11 Jun 2009 22:01:02 -0400, Rick Rothstein sez:
IF a user were to modify
an older file in the directory for some reason, then that file would
have a later "modified date" than the true last created file.


Hmmm, I had not thought about that. As it happens, I do save the files
with the date encoded as part of the file name, but using text months
("foobar_April_13.xls"). I guess I could start from yesterday and work
backwards, looking for the first file that matches the encoded date in
the file name. Thanks!

--
Peter B. Steiger
Cheyenne, WY
If you must reply by email, you can reach me by placing zeroes
where you see stars: wypbs.**1 at gmail.com.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Get the most recent file from a directory

Is the date encoded in the file name in anyway?

--
Rick (MVP - Excel)


"Peter B. Steiger" wrote in message
. ..
I'm writing a VBA macro that compares data between the currently open
worksheet and the one produced the previous week. Right now the user has
to manually open the previous worksheet, but I thought it would be nifty
if I automatically open it.

So my question is, given a target folder cLocation and a pattern
"foo*.xls", how can I get the name of the most recent (prior to today)
matching file in that location?

--
Peter B. Steiger
Cheyenne, WY
If you must reply by email, you can reach me by placing zeroes
where you see stars: wypbs.**1 at gmail.com.


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
how do i delete a file from recent documents file in excel exile New Users to Excel 1 March 7th 09 01:59 AM
Importing most recent file wrcaz Excel Programming 2 May 27th 06 04:40 PM
Most Recent File problem - Help!! Wibs Excel Discussion (Misc queries) 1 November 20th 05 01:21 PM
~Recent File~ andibevan Excel Worksheet Functions 2 November 19th 04 08:52 PM
Locate Most Recent File andibevan Excel Programming 3 October 27th 04 12:13 PM


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

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

About Us

"It's about Microsoft Excel"