Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Last Workbook in A Folder

Teresa, this is procedure Dana DeLouis posted that I have modified a
little for my needs. It finds the 'Newest' or last file in a folder.

'################################################# #######
Public Sub OpenNewestFile(searchDir$)
Dim file20Dir$
'// Modified--Origionally posted by Dana DeLouis
'// The first search is a workaround for an excel bug
'// in order to actually do the search you want
With Application.FileSearch
'// Wake Excel up for msoSortByLastModified to work !
..NewSearch
..LookIn = "C:\"
..FileName = "*.jnk"
..Execute SortBy:=msoSortBySize
End With
With Application.FileSearch
..NewSearch
'searchDir must be passed to the Sub
..LookIn = searchDir
..SearchSubFolders = False
..FileType = msoFileTypeExcelWorkbooks
If .Execute(SortBy:=msoSortByLastModified,
SortOrder:=msoSortOrderDescending) 0 Then
Dim nameArr As Variant
Dim myVar$, myFileName$
myVar = .FoundFiles(1)
nameArr = Evaluate("{""" & Application.Substitute( _
myVar, "\", """,""") & """}")
myFileName = nameArr(UBound(nameArr))

Response = MsgBox("The newest 20 file is " & myFileName & " created " _
& FileDateTime(.FoundFiles(1)) & ";Click OK to open; Click cancel to
select correct 20 file.", vbOKCancel)
If Response < 2 Then
Workbooks.Open .FoundFiles(1)
Exit Sub
Else
file20Dir = ""
MsgBox "Select the 'Current' download file."
On Error GoTo 0
file20Dir = Application.GetOpenFilename
If file20Dir = "False" Then
MsgBox "You failed to select the 20 file. This will end the process.",
vbOKOnly
Exit Sub
End If
Call fOpen(file20Dir)
End If
Else
MsgBox "There was no 20 file found, select the 'Current' 20 file."
file20Dir = ""
MsgBox "Select the Latest '20 file'."
On Error GoTo 0
file20Dir = Application.GetOpenFilename
If file20Dir = "False" Then
MsgBox "You failed to select the 20 file. This will end the process.",
vbOKOnly
Exit Sub
End If
Call fOpen(file20Dir)
End If

End With
End Sub
'################################################# #######

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
Workbook saved in FTP folder AP[_3_] Excel Discussion (Misc queries) 2 January 5th 09 12:53 PM
Link with workbook in other folder which is in another group Frank Situmorang Excel Discussion (Misc queries) 3 April 5th 07 05:50 AM
for every workbook in folder Patrick Excel Programming 2 November 27th 04 09:45 AM
Do same thing to each workbook found in a folder KENNY Excel Programming 4 October 8th 04 03:03 PM
New Folder, Workbook, and Worksheet [email protected] Excel Programming 1 September 14th 04 05:30 PM


All times are GMT +1. The time now is 12:15 PM.

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"