Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 177
Default Opening newest file

Hi All,

I am trying to write a macro that opens the newest file in a directory,
currently the files name contains the date in YYYYMMDD format and is run on a
weekly basis

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default Opening newest file

Assuming you know the year and month, maybe you could start with something
like this:

FileName = Dir$("200410*.XLS")
LastFile = ""
Do While Len(FileName) 0
If FileName LastFile Then
LastFile = FileName
End If
FileName = Dir$()
Loop

Or, if the files are written on the same day of the week, you should be able
to construct a list of the possible dates. If you create that list in
descending order, you can look for the files with the Dir$ command until you
find one. Assuming they are written on the 28th, 21st, 14th, and 7th

D = DateSerial(2004,10,28)
Do
If Len(Dir$(Format$(D, "yyyymmdd") & ".XLS")) Then Exit Do
D = D - 7
Loop

FileName = Format$(D, "yyyymmdd") & ".XLS"




On Thu, 4 Nov 2004 18:55:01 -0800, "Todd"
wrote:

Hi All,

I am trying to write a macro that opens the newest file in a directory,
currently the files name contains the date in YYYYMMDD format and is run on a
weekly basis

Thanks


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
Excel 2003 is Better than Newest Ones!? Mike Excel Discussion (Misc queries) 7 October 29th 09 09:48 PM
reporting newest/highest value Resi Excel Worksheet Functions 11 March 12th 09 10:11 PM
Filtering by newest date Al Excel Discussion (Misc queries) 2 November 12th 08 05:05 PM
opening an excel file opens a duplicate file of the same file skm Excel Discussion (Misc queries) 1 December 7th 05 05:52 PM
SV: Check for newest *.txt file and import data ALK Excel Programming 0 April 2nd 04 10:16 AM


All times are GMT +1. The time now is 01:58 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"