A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Open Last Modified File form Location



 
 
Thread Tools Display Modes
  #1  
Old December 9th, 2009, 10:58 AM posted to microsoft.public.excel.misc
Kam
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  
Old December 9th, 2009, 11:51 AM posted to microsoft.public.excel.misc
Jacob Skaria
external usenet poster
 
Posts: 5,952
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  
Old December 9th, 2009, 02:45 PM posted to microsoft.public.excel.misc
מיכאל (מיקי) אבידן
external usenet poster
 
Posts: 562
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  
Old December 9th, 2009, 05:26 PM posted to microsoft.public.excel.misc
מיכאל (מיקי) אבידן
external usenet poster
 
Posts: 562
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  
Old December 30th, 2009, 05:47 PM posted to microsoft.public.excel.misc
Randi R
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
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 12:54 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 OfficeFrustration.
The comments are property of their posters.