Count File Names

Hi All,

I having an issue with version control on Buisness cases. I currently
have a spreadsheet that looks into a folder and picks up details from
a number of files. However, they require version control numbers so
there will eventually be multiple files say 2010-01 v1.0, 2010-01
v1.1. Is there a way I can:

1) Get a macro to count the number of 2010-01 files there are in the
folder, and
2) Get my version control sheet to look at the latest version of the
file (in this example: 2010-01 v1.1)

Cheers,

Chris
0
Chris
1/13/2010 11:04:55 AM
excel.programming 6508 articles. 2 followers. Follow

3 Replies
602 Views

Similar Articles

[PageSpeed] 45

See if this code works.  I assume that 2010-01 is year and month.


Sub GetLatestFile()


Folder = "c:\temp\"

LatestDate = 0
LatestVersion = 0
LatestFName = ""

'make sure folder name has last backslash
If Right(Folder, 1) <> "\" Then
Folder = Folder & "\"
End If

CountYear = 0
FName = Dir(Folder & "*.xls")
Do While FName <> ""
'split file name into two piece around the space
NewVersionArray = Split(FName, " ")
'spit the date portion of the file name into year and month
NewDateArray = Split(Trim(NewVersionArray(0)), "-")
'convert the date to a number (serial date), use the first day of
the month
NewDate = DateSerial(NewDateArray(0), NewDateArray(1), 1)

'count if file is this year
If Year(NewDate) = 2010 Then
CountYear = CountYear + 1
End If

'remove the V from verion so version is a number
NewVersion = Val(Mid(Trim(NewVersionArray(1)), 2))

If NewDate > LatestDate And _
NewVersion > LatestVersion Then

LatestDate = NewDate
LatestVersion = NewVersion
LatestFName = FName
End If

FName = Dir()
Loop

'add folder name to latest file name
LatestFName = Folder & LatestFName


End Sub


-- 
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=169466

[url=&quot;http://www.thecodecage.com&quot;]Microsoft Office Help[/url]

0
joel
1/13/2010 11:55:22 AM
Hi Joel,

Thanks for this, it does work however, I haven't been explcit enough
in my original email.

The identifier for the file isn't quite year & month; you are right in
that 2010 is the year, however the second is just a sequential
reference number. So I would only want the macro to count 2010-01 as a
group, then 2010-02. So from the example above it would say that I
have 2 x 2010-01 files and the latest version is v1.1.

I have tweaked the macro, it runs, but does not give me any count
values in column E? I know it is going to be something simple, but no
error is coming up and I can't see where I have gone wrong (it also
might be slight inefficient!)

Here's the code:

Sub GetLatestFile()

Dim MyLr As Long
Dim Consh As Worksheet

Set Consh = Sheets("Reporter")

MyLr = Consh.Cells(Rows.Count, "b").End(xlUp).Row

Folder = "c:\"

LatestDate = 0
LatestVersion = 0
LatestFName = ""

'make sure folder name has last backslash
If Right(Folder, 1) <> "\" Then
Folder = Folder & "\"
End If

If myLR1 < 9 Then
    myLR1 = 9
End If

For r = 9 To MyLr

CountFile = 0
FName = Dir(Folder & "*.xls")
Do While FName <> ""
'split file name into two piece around the space
NewVersionArray = Split(FName, " ")
'spit the date portion of the file name into year and month
NewDateArray = Split(Trim(NewVersionArray(0)), "-")
'convert the date to a number (serial date), use the first day of
'the Month
NewDate = DateSerial(NewDateArray(0), NewDateArray(1), 1)

If NewVersionArray(0) = Consh.Cells(r, "B").Value Then
CountFile = CountFile + 1
Consh.Cells(r, "E") = CountFile

End If

'remove the V from verion so version is a number
NewVersion = Val(Mid(Trim(NewVersionArray(1)), 2))

If NewDate > LatestDate And _
NewVersion > LatestVersion Then

LatestDate = NewDate
LatestVersion = NewVersion
LatestFName = FName
End If

Cells(r, "F") = NewVersion

FName = Dir()
Loop

'add folder name to latest file name
LatestFName = Folder & LatestFName

Next r

End Sub


Thanks Again.

Chris
0
Chris
1/13/2010 1:32:24 PM
On Jan 13, 1:32=A0pm, Chris <chrisb...@hotmail.com> wrote:
> Hi Joel,
>
> Thanks for this, it does work however, I haven't been explcit enough
> in my original email.
>
> The identifier for the file isn't quite year & month; you are right in
> that 2010 is the year, however the second is just a sequential
> reference number. So I would only want the macro to count 2010-01 as a
> group, then 2010-02. So from the example above it would say that I
> have 2 x 2010-01 files and the latest version is v1.1.
>
> I have tweaked the macro, it runs, but does not give me any count
> values in column E? I know it is going to be something simple, but no
> error is coming up and I can't see where I have gone wrong (it also
> might be slight inefficient!)
>
> Here's the code:
>
> Sub GetLatestFile()
>
> Dim MyLr As Long
> Dim Consh As Worksheet
>
> Set Consh =3D Sheets("Reporter")
>
> MyLr =3D Consh.Cells(Rows.Count, "b").End(xlUp).Row
>
> Folder =3D "c:\"
>
> LatestDate =3D 0
> LatestVersion =3D 0
> LatestFName =3D ""
>
> 'make sure folder name has last backslash
> If Right(Folder, 1) <> "\" Then
> Folder =3D Folder & "\"
> End If
>
> If myLR1 < 9 Then
> =A0 =A0 myLR1 =3D 9
> End If
>
> For r =3D 9 To MyLr
>
> CountFile =3D 0
> FName =3D Dir(Folder & "*.xls")
> Do While FName <> ""
> 'split file name into two piece around the space
> NewVersionArray =3D Split(FName, " ")
> 'spit the date portion of the file name into year and month
> NewDateArray =3D Split(Trim(NewVersionArray(0)), "-")
> 'convert the date to a number (serial date), use the first day of
> 'the Month
> NewDate =3D DateSerial(NewDateArray(0), NewDateArray(1), 1)
>
> If NewVersionArray(0) =3D Consh.Cells(r, "B").Value Then
> CountFile =3D CountFile + 1
> Consh.Cells(r, "E") =3D CountFile
>
> End If
>
> 'remove the V from verion so version is a number
> NewVersion =3D Val(Mid(Trim(NewVersionArray(1)), 2))
>
> If NewDate > LatestDate And _
> NewVersion > LatestVersion Then
>
> LatestDate =3D NewDate
> LatestVersion =3D NewVersion
> LatestFName =3D FName
> End If
>
> Cells(r, "F") =3D NewVersion
>
> FName =3D Dir()
> Loop
>
> 'add folder name to latest file name
> LatestFName =3D Folder & LatestFName
>
> Next r
>
> End Sub
>
> Thanks Again.
>
> Chris

Just an Update, Have now got the Filename count to work perfectly,
just re-entered the values in the cells and it worked fine, now just
having an issue with the latter version control section.

Cheers
0
Chris
1/13/2010 2:02:33 PM
Reply:

Similar Artilces:

#Delete Mark in Bound Memo filed
I have form that has bound memo field, sometime, no sure how it happen, the memo filed is filled with #Delete. My application is a stand alone program. Kindly advise what can cause this and how to avoid it from happening. -- TS Lim When was the last time you performed a compact and repair? Is you db split? Does each user have their own copy of the front-end? Please checkout http://www.granite.ab.ca/access/corruptmdbs.htm http://www.granite.ab.ca/access/corruption/symptoms.htm http://office.microsoft.com/en-ca/access/HA011865661033.aspx - No very helpful but directly from MS ...

CSV File Problem
Can any one explain why the following problem occurs please? A colleague has a small list of data which is a csv file exported from SQL. Column One is a serial number from 1 to 29. Column 2 is a number of transactions which have occurred.(it should look like example A below in Excel) 1 475 1,475 2 1732 21,732 3 1670 31,670 4 2176 42,176 5 608 5,608 6 1579 61,579 7 43101 743,101 8 54512 854,512 9 51258 951,258 10 61050 1,061,050 A B If I double click on the csv file, it opens in Excel but c...

CFile (delete file)
How can I delete all files that end with ".temp" in some folder? CFile::Remove remove unlink -- cheers, Alok Gupta Blogs: http://wdevs.com/thatsalok "Petar Popara" <my.fake@mail.net> wrote in message news:Op6#URKfFHA.2644@TK2MSFTNGP09.phx.gbl... > > How can I delete all files that end with ".temp" in some folder? > > SHFileOperation() will and it supports wildcards! DeleteFile() will operate on one file at a time. "Petar Popara" <my.fake@mail.net> wrote in message news:Op6%23URKfFHA.2644@TK2MSFTNGP09.phx.gbl... > >...

Opening an *.MSG file with it's respective attachment.
Hello, The file *.MSG is a message file. This can be viewed by any editor, like Notepad. However, when there's an attachment to it, we see garbage. Is there a way to open the attachments present inside the *.MSG files ? Thank you Yes, by opening it with Outlook. -- Roady [MVP] www.sparnaaij.net Microsoft Office and Microsoft Office related News Also Outlook FAQ, How To's, Downloads and more... Tips of the month: -Create your own fully customized Toolbar -Creating a Classic View in Outlook 2003 Subscribe to the newsletter to receive news and tips & tricks in your mailbox!...

Can't open 2005 data file after reinstalling Money 2005
I am experiencing a recurring problem. I have had to reinstall Windows XP and MS Money 2005. I am now unable to open my previously converted 2005 file or restore any backup version. I consistently get the following error message: "Money cannot locate filename or cannot open it, possibly because it is a read-only file, you do not have permission to change it, or your disk drive is write- protected. If you have chosen the correct file and it cannot be accessed, you will need to click OK and then Restore your most recent backup file." Any help or thoughts would be greatly ap...

import a 123 file
My excel version cannot open a Lotus 123 file. Is there an import feature to move the data from Lotus 123 to Excel? Thanks No, you need to convert the file either from Lotus 123 or get commercial converter -- Regards, Peo Sjoblom "Frank" <Frank@discussions.microsoft.com> wrote in message news:59B55F98-4C79-4917-928B-F1B309660730@microsoft.com... > My excel version cannot open a Lotus 123 file. Is there an import feature > to > move the data from Lotus 123 to Excel? > Thanks > > ...

Where is the cache files folder located for windows media player?
Does windows media player have a cache files folder? Where is the cache files folder located for windows media player? Or how do I find the cache files folder for windows media player? Thank You for your Help. Bob Background info: I have a desktop AMD 4400+ 64X2 4GB memory 320GB HD(way bigger than I need) Acer computer (AM3100-U3201A) I purchased new February 2008 running 32-bit MS Vista Home Premium SP2 box. I use MS auto updates. I think it has onboard shared memory for video and sound. My ISP is Comcast 12mbps with Motorola SURFboard SB5101 Cable Modem direct to...

Public Folder link to Excel File
Hi - I have a user that claims that he had a shortcut to a spreadsheet "in his public folders" at his old job. Obviously, he's an end user that may or may not know what he's talking about.... I'm trying to figure out the best way to accomodate him. He basically wants an Excel file stored on a shared folder to be available to all user as either a shortcut, or a link in the public folders (can't post to a folder as he will be updating the sheet regularly). When a user clicks on the shortcut/link, it would just launch Excel and display the file. Anybody have any ideas...

Opening pub files created with older Publisher versions #2
I have just upgraded to Publisher 2003 from 2000 and am having trouble with pub files sent to me for our chuch newsletter which is using Publisher 97 The text is not wrapping around graphics boxes. Can I fix this? I really don't want to go back to Pub 200 Thank Richard this is caused by Publisher 97 not been printer independent. Even if you went back to Publisher 2000, unless you have the identical font versions and printer driver you would have issues with formatting. It sounds like the person sending you the file has a garbage HP inkjet printer. Get them to install the HP5P laser p...

Renaming Partial File Names
Is it possible to rename part of a file name? (almost like a find and replace) My database pulls in the excel file names from a directory, with it's subfolders and contents as well. Every file begins with "Kay Form". Kay no longer works in our department, and I'd like to run a loop that replaces "Kay Form" with "Featured Track". I don't know how to do a partial replace though. Thank you in advance! -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access/201001/1 Checkout the Replace function. I...

printing imported gif files in Excel
When printing gif file with transparent background on the grey(25%) background of Excel non-transparent part of the picture has white border around it. Is there any way to prevent it? Thank you in advance... Tim ...

unknown .edb file
I have error messages in the log files that references a corrupt database named C:\Program Files\exchsrvr\Exchangeserver_Outlook.edb. "Outlook" is the name of the server. The problem is that this database is not listed in any of the Mail Stores or Public stores. I want to run the repair utilities on it, but since I'm not sure what it is used for, I don't know how I can restore it if the repair goes bad. Does anyone know what this is used for or how I can determine that myself? BTW, the database always has a current time stamp, so I assume that it is used by something....

Copying dbx files from a CDR back into Outlook
My computer was recently hijakced and I had to reinstall everything. I did however save all of my folders in Outlook onto a CD Rom and I do not know how to transfer them back so I can use them. Also I had an animated version of outlook where you could choose loads of diffent stationery and I cannot seem to find that upgrade anaywhere. Can you help me? Tee <tsahai33@hotmail.com> wrote: > My computer was recently hijakced and I had to reinstall > everything. I did however save all of my folders in > Outlook onto a CD Rom and I do not know how to transfer > them back so...

Shortcut for inserting names?
Hi, I am building many formulas, each with many named cells as part of it. Currently I have to go to Insert | Name | Paste with the mouse each time I want to insert a name. I looked in Walkenbach's Excel Bible but couldn't find any mention of a keyboard shortcut or other shortcut. Is there one I could take advantage of? I've got Excel 2002. Thanks, Jamie ...

DB_Backup.MDB file has appeared beside DB.MDB.
I have a local DB.MDB which accesses a DATA.MDB on a network drive. I use a user-level security file. It has been working AOK for a year or so. Yesterday one of the users reported an error dialog when attempting to open the DB.MDB (unfortunately the wording of the dialog was not captured!) After this 'event', the database started working correctly once again. The result was a DB_Backup.MDB file appeared beside the DB.MDB. Any ideas? That backup file is created when ACCESS "crashes" during use..... -- Ken Snell <MS ACCESS MVP> "Andrew (UGL)&quo...

Indirect Method for Name Box Variable? #2
DARN The reason I want to do this is that I have to collect data on a dail basis but I have to display it on a graph on a weekly basis. I select the entire week of cells and give it a name like week52. The following week I have to select the entire week and name i week53. Everything is set up that I can just copy and the numbers will progres for whatever length of time I need to graph (months, years, etc) excep this. Maybe I'll just go back to using the range of cell numbers. Thanks guys -- Chris Brenna ----------------------------------------------------------------------- Chris Bre...

Archiving Outlook.pst files to Novell Netware file server
Hi all We are trying to perform a manual Outlook inbox archive which we are tryingto save to a Novell file server - but it dowsn't work. Any ideas why? (works fine on the MS2000 server but we don't have the space for everyone) We are currently running Outlook 2003 and the Novell file server is 4.8.3 Any help would be appreciated Thanks!! kwan <kevin.kelly@levittbernstein.co.uk> wrote: > We are trying to perform a manual Outlook inbox archive which we are > tryingto save to a Novell file server - but it dowsn't work. Any ideas > why? (works fine on the MS2000 s...

Sorting by file extension in a worksheet
Hello, I have an excel worksheet which has a list of file names from a directory and various stats about each file. I need to be able to sort them by the file extension. Eg. c:\documents\folderA\picture1.eps c:\documents\folderB\document.doc I would like to sort them by the ".eps" extension. I have tried using the Data,Sort menu and something like *?*.eps as the criteria. But am obvisouly missing something. Any help would be most appreciated. Thanks Karl You could use a helper column to extract just the extension then include this in your sort range and sort on the helper col...

How to use count for calls per hour
I am trying to create a pivot table and chart that will show me the # of calls per hour by day for a range of dates Aug 1 - Sept 19. My data looks like this where each line is the date and time of the call: How do I get a count of the # of the calls per hour by day? 8/1/08 12:48 AM 8/1/08 1:53 AM 8/1/08 2:36 AM 8/1/08 3:24 AM 8/1/08 3:37 AM 8/1/08 4:04 AM 8/1/08 4:44 AM 8/1/08 4:55 AM 8/1/08 4:58 AM 8/1/08 7:02 AM 8/1/08 7:28 AM 8/1/08 7:43 AM 8/1/08 7:47 AM 8/1/08 7:56 AM 8/1/08 7:58 AM 8/1/08 8:13 AM 8/1/08 8:33 AM 8/1/08 9:07 AM 8/1/08 10:28 AM 8/1/08 10:38 AM 8/1/08 10:44 AM 8/1/08 ...

If a worksheet name is = to test then a msgbox appears
I'm looking for a macro that will display a msgbox if a worksheet is = to test. For example, if the name of a sheet in a workbook is equal to test then display msgbox saying sheet already exists. Thanks Vick dim ws as worksheet set ws = nothing on error resume next set ws = worksheets("test") on error goto 0 if ws is nothing then msgbox "doesn't exist" else msgbox "already exists" end if Vick wrote: > > I'm looking for a macro that will display a msgbox if a worksheet is = to test. > > For example, if the name of a sheet in a w...

Outlook 2007 PST files and temp files
When I have PST files on the server, I notice that there is a temp file accompanying it when Outlook is loaded. Would loading the temp file on the local PC make Outlook quicker, if so, how can one do this...? Thanks, Tom... "TK" <tkarpowski@bennettcompany.com> wrote in message news:Ovq2RUgvJHA.1088@TK2MSFTNGP04.phx.gbl... > When I have PST files on the server, I notice that there is a temp file > accompanying it when Outlook is loaded. > > Would loading the temp file on the local PC make Outlook quicker, if so, how > can one do this...? You shouldn...

crop files
I've a file with this structure Code value 0001 dfdf 0002 ddgdfg 0001 dsdfsd 0001dfdgdsgds 0002 defert I'd like to crop this file in 2 different files ..one for 0001 and the other for 0002 with of course Code value for both and then block a cell in both. the name of the file and the name of the sheet should be given with a textbox input and they will be the same for both.. the directory will be the same of the main file. any hints?? or a guide I should follow since I'd like to learn and do everything by myself??? thanks Rossella Try Data>Filter>Advanced Filter HTH -- AP ...

Loading Text File to TextBox using LoadFromFile
Hi All, I'm creating a form that allows the user to pick a txt file (dialog) and then display the path and contents on the form. The code has been cobbled together as I found the pieces that worked, so bear with. I got the file picker working and displaying the file name on the form, but the file contents won't display. I had a feeling the problem had to do with importing a namespace (see the error in the code when I tried "Imports System.IO") or with a missing reference. Using Access 2003. References: VB for Apps, MS Access 11 Obj Lib, OLE Auto, MS V...

Publisher file size #2
I created a publisher file with one 800k picture, a little text, and a border. The file turned out to be 11 megs! Why is this so? rainman33 wrote: > I created a publisher file with one 800k picture, a little text, and a > border. The file turned out to be 11 megs! Why is this so? You are using Publisher 2000 or earlier (or possibly 2002). Publisher 2000 and earlier decompress all pictures and save them as uncompressed bitmap images, inflating small JPEG files the most. Publisher 2002 decompresses images and then recompresses them as PNGs, which inflates JPEGs quite a bit ...

changing a cell of 60 files
Hi all I've 60 files and another one which summarizes all of them.. I've to put a day in the cell a1 and then I'd like to cut and paste that day in the cell a1 of the other 60 files without having to change all of them manually. I'd like to save and then exit every single file.The files are named 0001 0002 0003..and so on. I know that this is possible with a macro..but I've got a problem.. It's possible not to have the prompt which asks for updates of the file everytime I open one of them?? Thanks for the help Rossella Hi Rossella http://www.rondebruin.nl/copy4.htm ...