Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Kam Kam is offline
external usenet poster
 
Posts: 57
Default Open Last Modified File form Location

Hi,

I have one folder, which has 20 files & I want macro to open last modified
file in that folder. Is this can be done??

File Path: C:\Users\Glenys\Desktop\Glen_Macro\

Best Regards,
Kam.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Open Last Modified File form Location

One way using Dir()..

Sub LastModifiedFilewithinFolder()

Dim strFile As String, strFolder As String
Dim dtLast As Date, strLMFile As String

strFolder = "C:\"
'strFolder = "C:\Users\Glenys\Desktop\Glen_Macro\"
strFile = Dir("c:\*.*", vbNormal)
Do While strFile < ""
If FileDateTime(strFolder & strFile) dtLast Then
dtLast = FileDateTime(strFolder & strFile)
strLMFile = strFolder & strFile
End If
strFile = Dir
Loop

MsgBox "Last Modified file is : " & strLMFile

End Sub


--
Jacob


"Kam" wrote:

Hi,

I have one folder, which has 20 files & I want macro to open last modified
file in that folder. Is this can be done??

File Path: C:\Users\Glenys\Desktop\Glen_Macro\

Best Regards,
Kam.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 561
Default Open Last Modified File form Location

In order to OPEN(!) the last modified file he'll need the command listed below:
Workbooks.Open (strLMFile)
Micky


"Jacob Skaria" wrote:

One way using Dir()..

Sub LastModifiedFilewithinFolder()

Dim strFile As String, strFolder As String
Dim dtLast As Date, strLMFile As String

strFolder = "C:\"
'strFolder = "C:\Users\Glenys\Desktop\Glen_Macro\"
strFile = Dir("c:\*.*", vbNormal)
Do While strFile < ""
If FileDateTime(strFolder & strFile) dtLast Then
dtLast = FileDateTime(strFolder & strFile)
strLMFile = strFolder & strFile
End If
strFile = Dir
Loop

MsgBox "Last Modified file is : " & strLMFile

End Sub


--
Jacob


"Kam" wrote:

Hi,

I have one folder, which has 20 files & I want macro to open last modified
file in that folder. Is this can be done??

File Path: C:\Users\Glenys\Desktop\Glen_Macro\

Best Regards,
Kam.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 561
Default Open Last Modified File form Location

A slightly another approach:
Sub OpenLastModifiedFilewithinFolder()
On Error Resume Next
With Application.FileSearch
.LookIn = "C:" : .Filename = "*.XLS*"
If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending)
0 Then

For FF = 1 To .FoundFiles.Count
If FileDateTime(.FoundFiles(FF)) LastModDate Then
LastModDate = FileDateTime(.FoundFiles(FF))
LMF = .FoundFiles(FF)
End If
Next
End If
End With
Workbooks.Open (LMF)
End Sub
============
Micky


"מיכאל (מיקי) אבידן" wrote:

In order to OPEN(!) the last modified file he'll need the command listed below:
Workbooks.Open (strLMFile)
Micky


"Jacob Skaria" wrote:

One way using Dir()..

Sub LastModifiedFilewithinFolder()

Dim strFile As String, strFolder As String
Dim dtLast As Date, strLMFile As String

strFolder = "C:\"
'strFolder = "C:\Users\Glenys\Desktop\Glen_Macro\"
strFile = Dir("c:\*.*", vbNormal)
Do While strFile < ""
If FileDateTime(strFolder & strFile) dtLast Then
dtLast = FileDateTime(strFolder & strFile)
strLMFile = strFolder & strFile
End If
strFile = Dir
Loop

MsgBox "Last Modified file is : " & strLMFile

End Sub


--
Jacob


"Kam" wrote:

Hi,

I have one folder, which has 20 files & I want macro to open last modified
file in that folder. Is this can be done??

File Path: C:\Users\Glenys\Desktop\Glen_Macro\

Best Regards,
Kam.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default How to find and open the latest modified file


Kam

I have one folder, which has 20 files &
I want macro to open last modified
file in that folder. Is this can be done??

File Path: C:\Users\Glenys\Desktop\Glen_Macro\



Not a macro, but a script. I have added comments so you can transfer the logic to a macro.




# Script OpenLast.txt
var str list, file, latestfile, latesttime
# Go to the desired folder.
cd "C:\Users\Glenys\Desktop\Glen_Macro"
# Collect a list of files
lf -r -n "*" ($ftype=="f") $list
# Go thru files one by one, checking mod time of each.
while ($list < "")
do
# Get the next file from the list.
lex "1" $list $file
# Get mod time.
af $file null
# Mod time is now in $fmtime. Is it later than $latesttimg ?
if ($fmtime $latesttime)
do
# Yes, save this as the latest file.
set $latestfile = $file
set $latesttime = $fmtime
done
endif
done
# We now have the latest modified file in $latestfile. Open it.
system start ("\""+$latestfile+"\"")





Above script is in biterscripting ( http://www.biterscripting.com ). To try it before you make it into a macro, save the script in file C:/Scripts/OpenLast.txt, enter the following command in biterscripting.



script "C:/Scripts/OpenLast.txt"








Kam wrote:

Open Last Modified File form Location
09-Dec-09

Hi,

I have one folder, which has 20 files & I want macro to open last modified
file in that folder. Is this can be done??

File Path: C:\Users\Glenys\Desktop\Glen_Macro\

Best Regards,
Kam.

Previous Posts In This Thread:

On Wednesday, December 09, 2009 5:58 AM
Kam wrote:

Open Last Modified File form Location
Hi,

I have one folder, which has 20 files & I want macro to open last modified
file in that folder. Is this can be done??

File Path: C:\Users\Glenys\Desktop\Glen_Macro\

Best Regards,
Kam.

On Wednesday, December 09, 2009 6:51 AM
Jacob Skaria wrote:

One way using Dir()..
One way using Dir()..

Sub LastModifiedFilewithinFolder()

Dim strFile As String, strFolder As String
Dim dtLast As Date, strLMFile As String

strFolder = "C:\"
'strFolder = "C:\Users\Glenys\Desktop\Glen_Macro\"
strFile = Dir("c:\*.*", vbNormal)
Do While strFile < ""
If FileDateTime(strFolder & strFile) dtLast Then
dtLast = FileDateTime(strFolder & strFile)
strLMFile = strFolder & strFile
End If
strFile = Dir
Loop

MsgBox "Last Modified file is : " & strLMFile

End Sub


--
Jacob


"Kam" wrote:

On Wednesday, December 09, 2009 9:45 AM
????? (????) ????? wrote:

In order to OPEN(!
In order to OPEN(!) the last modified file he will need the command listed below:
Workbooks.Open (strLMFile)
Micky


"Jacob Skaria" wrote:

On Wednesday, December 09, 2009 12:26 PM
????? (????) ????? wrote:

A slightly another approach:Sub OpenLastModifiedFilewithinFolder()On Error
A slightly another approach:
Sub OpenLastModifiedFilewithinFolder()
On Error Resume Next
With Application.FileSearch
..LookIn = "C:" : .Filename = "*.XLS*"
If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending)
For FF = 1 To .FoundFiles.Count
If FileDateTime(.FoundFiles(FF)) LastModDate Then
LastModDate = FileDateTime(.FoundFiles(FF))
LMF = .FoundFiles(FF)
End If
Next
End If
End With
Workbooks.Open (LMF)
End Sub
============
Micky


"?????????? (????????) ??????????" wrote:


Submitted via EggHeadCafe - Software Developer Portal of Choice
Extending the DataAdapter with a Helper Class
http://www.eggheadcafe.com/tutorials...taadapter.aspx
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
VBA to ask for file location and use to open DB Brian Excel Worksheet Functions 4 May 15th 09 03:36 PM
Open Form when file opened Dana Excel Discussion (Misc queries) 2 July 25th 08 04:36 PM
Open File from FTP Location Bricol Excel Discussion (Misc queries) 3 January 9th 08 02:58 PM
Excel File Open Box - want Date Modified Titian Excel Discussion (Misc queries) 2 February 26th 06 08:25 AM
Open Form Automatically in Excel File Bejewell New Users to Excel 1 November 16th 05 06:18 PM


All times are GMT +1. The time now is 09:29 PM.

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"