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.
0
Utf
12/9/2009 10:58:01 AM
excel.misc 78881 articles. 5 followers. Follow

4 Replies
2563 Views

Similar Articles

[PageSpeed] 47

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.
0
Utf
12/9/2009 11:51:01 AM
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.
0
Utf
12/9/2009 2:45:01 PM
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.
0
Utf
12/9/2009 5:26:01 PM
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/aspnet/7e8fa474-6909-4310-b778-d5e53a43f8f1/extending-the-dataadapter.aspx
0
Randi
12/30/2009 5:47:15 PM
Reply:

Similar Artilces:

Exporting One File to Two Others
Here's the situation - hopefully someone can answer my question or come up with a better idea. My daughter owns a used book store and has and inventory of over 10,000 books. My thoughts were to have three different files for serch purposes. ie Title, Auther, Subjuct Matter and add a Referance Number to each book. This way if a customer askes for a book, the serch would be easy. The problem lies in the sales. When a customer purchases a book, she would write down the Referance Number on a sheet of paper then at the end of the day, enter all the days Reference Number into the fi...

Main Form checkbox toggles many subform checkboxes
I have a main form / subform setup. The subform has a field that is a yes/no data type, represented by a checkbox in the field. How do I set up a control on the main form (possibly another checkbox) so that when I click the control, it will toggle ALL of the checkboxes in the subform on and off. Similar to a "select/deselect all"? -- Message posted via http://www.accessmonster.com Use the AfterUpdate event procedure of the unbound check box on the main form, to execute an Update query on the subform's table. This kind of thing: Private Sub chkSetAll_AfterUpdate() Dim ...

Rules Wizard does not open.
Hello all, I have a user that when he clicks the organize button and then when that expands out he trys to click the Rules Wizard button and nothing happens. Also Rules Wizard does not show up in the Tools menu. He is using Outlook 2002 SP-1. Does anyone have any clues? Thanks, Jay ...

Form type in a public folder
need to create a folder on a server and have been told I have more control over replication and where it is created if I use exchange manager. This seems to be true and fairly straightforward except I do not know how you create a folder to accept a particular type of form (e.g. Task). The point you do that when you create one in outlook is when you select "New" and you pick the form type from the drop down. I don't know if you can change the form type for an already exising folder. I do not mean the specific form type for a new item (eg ipm.task.custom form) I mean the general...

missing folders! can't import archive.pst file!
help! i made an archive.pst file to back up my folders. then i moved my personal folders from under the "outlook today" folder to under a new "personal folders" folder. they were there. it was fine. then i closed and re- started outlook, and they were gone! and i tried to view and/or import the archive.pst file, but it didn't work! help! -marie What happens if you search for the .pst file after enabling searching hidden and system folders? --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. After searching goo...

MS Outlook crashes Windows when importing large pst file
I recently had to reinstall MS office and Win2K on my PC because of a virus attack. I was able to import old archive pst files into outlook 2000 that were relatively small (<1 GByte). My most recent pst archive which had grown to 1.89 Gbytes crashes the Operating System (WIn2K) when I try to import it. As far as I can determine it is free of viruses/worms and has been scanned by the same SW (Network associates) that repaired my PCs. The MS utility to read large pst files (supplied on the MS support website) does not work - it needs a file that is a minimum of 2 GB. The Windows uti...

how can Modify the Restock Quantity of a Purchase Order...
Hello to all. is there a way to modify a Purchase order in order to have it to have the Reorder Quantity equals to the Restock Quantity? For Instance: I have a stock of quantity 2 of a given item in the store at the moment of make the PO, and I have my restock Level set to 12. it will give me by default a order of 10 (2+10=12)... but in the warehouse I have the 12 packs of that item, so I would like to have my Purchase order to order one more time the same 12 Items in order to restock it directly from the warehouse's 12 pack.. Thanks in advance. Aldo Aldo, I'm not sure I fol...

Winhttp.h file
Hi I want to use 'WinHttpGetProxyforurl' method to retrieve the proxy information from a pac file.But I couldnot found the winhttp.h, winhttp.lib and winhttp.dll files to compile it. please send me if any other solution to get proxy information from pac url. Any help will be appreciated. Thanks you Dinraj Did you install the Platform SDK? If not install it. WinHttp.h is a copyrighted source owned by Microsoft, and as such is not distributable by sending you a copy without violating our license agreement with Microsoft. If you or your company has not done so already, you wil...

Filter of subfirm of sencond form
Hello all Expert I have write vba code to filter the subform but i can't as below -i have one form when click on button on this form show another form that have subform so i want to filter this subform but it is not working. can you help me how to do it working? Thanks. ...

Exel 2002 freezes when opening sheet
Hi Have office XP, windows XP pro, latest service packs. When opening a word or exel document from the file/Open menu and select previous documents opened at the bottom of the menu the first time it takes forever and freezes the machine while waiting, after that it will open OK. Regards Grant ...

Dexterity Runtime: You do not have permissions to open this file
So, I have a users that is getting: "Dexterity Runtime: You do not have permissions to open this file" I checked and I ensured that she has the same permissions on the network as other users and she can get to all the files in the GP directory on the server. I had the admin reset her password in Great Plains and that didn't work either. I had one of the other users log into her computer and it worked fine too. Any Clues. Is this happening when first logging into GP? If so, it's typically a Windows permission error on the reports.dic (usually this happens when it...

Can a form with drop down menus search in other forms?
I am trying to design a database to where the switchboard will lead to a form that has various drop down menus for searching purposes. Let's say that on this form, one of the companies in the "Company Name" drop down menu is Company A. I want for Access to pull all forms that have "Company A" in it. So for example, I would end up with 1 record displayed out of 25. Is this even possible? -- Natasha Well, you really search WITH forms; you don't search FOR forms. Maybe this will help. http://datapigtechnologies.com/flashfiles/searchform.html ...

opening excel from intranet ie6.0
I have a number of excel files I wish to share between multiple users. I can give them access to these files via our Intranet using Internet Explorer 6.0. My problem is that the excel files open up inside the browser, not in excel. I want user to click on the file in the Intranet IE6.0 and for the file to open in the Excel application (Excel 2000). Any ideas / help welcome. Thanks Paddy ...

The disappearing form
In using Access 2007, I have a database with five joined tables. I want to make a form, based on the "main table" and then four individual subforms. This works fine for the first of the four subforms, but when I add the second in design view, and then look at my handy work in Form View, all I have is a blank, white display, none of the controls are visible. This is the most complex form I have ever attempted and can not determine what is wrong. Please help. Paul If your form is blank, that generally means there was no data there to show. Make sure your control sour...

Unable to open excel file #2
Hi. I have problem openning an excel file from windows explorer or from my desktop. However, when I open the excel program and open a file manually(File-Open----) everything works fine. I get an error message that the file could not be located. I noticed that it adds .xls to every word separated by space. For example: My file is in C:/Shared/Folder/test.xls, it tries to open: C:/Shared.xls then Folder.xls then test.xls Please help. Thanks. --- Message posted from http://www.ExcelForum.com/ Hi! I think the steps below will solve this problem: 1. Exit Excel 2. From the Startmenu, cli...

mde file in Access 2007
I have just converted a mdb database in Access 2007 to a mde file, but now the said database does not work correctly. When I opened up the mde database, I got a message from Access 2007 saying there was a potential security concern, and I clicked the ok button to open up the database. Now the combo box to find records does not function, as when I select a record from the list, it is not shown on the form. Thanks On Sun, 30 May 2010 18:00:40 +0100, Bob H <bob@despammer.com> wrote: Did you put the database in a Trusted Location (see help file)? -Tom. Microsoft Access M...

Exchange 2003 Forms Logon
Hi there.... I am trying to have exchange 2003 view forms when using the webmail client to logon, I set it to use forms in exchange system manager, but upon login.... no forms :/ just a dialog box to logon... Can anyone help? thanks alot in advance Rudi Groenewald wrote: > Hi there.... > > I am trying to have exchange 2003 view forms when using the webmail > client to logon, I set it to use forms in exchange system manager, > but upon login.... no forms :/ just a dialog box to logon... > > > Can anyone help? I guess you mean Forms-based Authentication? Are you u...

Locking Fields in an Editable Form
Hello, I created a form that has the Allow Edits selected as Yes. But I only want 2 fields in the form to be editable, the remaining other fields I'd like them to be locked. Is there a way I can lock the other fields so that it's not changed? When I try to change the field property for Locked as Yes, it locks the field so that when I enter any new records it will not allow me to input data in that field. Can anyone suggest how I can modifiy my existing form so that it locks most of the fields after it's saved but allows edits to specific fields when going back on a record? Th...

Unable to open Exchange Systems Manager
When I double-click on the ESM on the desktop. I get the following error message. Error Message 1: The system cannot find the file specified Facility: Win32 ID no: c007002 Exchange System Manager Error Message 2: (This message appears after clicking on OK from message 1) Microsoft Visual C++ Runtime Library Runtime Error! Program: This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. Running Exchange 2003 with Windows 2003 "=?Utf-8?B?TWlrZSBDaHVuZw==?=" <MikeChung@discussions.m...

Open Puiblisher Document Without Program Installed
Is there a snap-in or some way to view a Publisher 2003 document without having the Publisher software installed? I know there is a viewer for Powerpoint slides and thought maybe there is something similiar for Publisher? I have done some searches and found nothing. Thanks in advance for any info. No, there isn't a Publisher viewer. Have your sender convert the publication to a PDF or a picture. There are free PDF converters around. You can download a trial version of Publisher 2007, when the trial runs out it will serve as a viewer. http://office.microsoft.com/en-us/publisher/FX...

Blocking .zip files
Is there any way to block certain extension files (besides the 66+ already blocked by default) on Exchange 2000 or should I use the server anti-virus settings for that ? use your AV... "Marlon Brown" <marlon_brown@hotmail.com> wrote in message news:e#aeScXAEHA.392@TK2MSFTNGP12.phx.gbl... > Is there any way to block certain extension files (besides the 66+ already > blocked by default) on Exchange 2000 or should I use the server anti-virus > settings for that ? > > You can either have your Server Exchange Aware Antivirus program do this or I have been sugge...

P-V chart, get the last date on the X axis?
In a Price-Volume chart, how do you get the last date of your data on the X axis to show up? Here's one way: http://www.arouet.net/archives/2004/08/show_the_datas.php You have to scroll down a bit, the page's layout is a little funny. If you don't care about the first date also showing, here's another way which may be marginally easier: Have your dates in descending order in the sheet. Create your chart. Go to Chart menu > Chart Options > Axes, change Category Axis to Category. Double click the X axis, Scale tab, select Categories in Reverse Order and if desired V...

delete log files
have a filled up drive- no need for logfiles in this instance circumstance would allow circular logging for next few months, before setting though, need to reclaim space on hdd. how to tell which logfiles I can delete and not hose the db? In news:14ABD827-B264-4626-8970-20E5578A4053@microsoft.com, AlexandrDiogenes@hotmail.com <AlexandrDiogeneshotmailcom@discussions.microsoft.com> typed: > have a filled up drive- no need for logfiles in this instance > circumstance would allow circular logging for next few months, before > setting though, need to reclaim space on hdd. how ...

Report Writer, Blank SOP Forms & MBoM Revision Levels
Hello, I am trying to add the revision level listed in table BM010415 of the Manufacturing Series to the Blank SOP Forms used in Dynamics GP. I am frustrated by the lack of capacity to relate GP Tables to Manufacturing Tables in the Report Writer. Can anyone offer any help? (Without using Modifier dependant VBA.) To go into further detail, I can link from the Manufacturing Series into standard GP tables; but I can't link from GP into Manufacturing, which forces the Manufacturing Tables to be primaries and inhibits the ability to reach into Manufacturing. I can add GP Data into...

unable to open information store
After a recent power failure, where the exchange server was not shut down properly and just died, I now have users, that used to be able to open other users inbox to read the emails, now not able to open these inboxes. the message is unable to open information store. The same also applies to callenders, but this is not happening to everyone, as I can still access other peoples folders. ...