#1   Report Post  
Posted to microsoft.public.excel.misc
Bear
 
Posts: n/a
Default Renaming Files

I have a great number of files labeled with a first name followed by a
last name and a date. I need to switch the file names and save them as
Last Name First Name followed by the date? Any suggestion on how to do
this?

  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Renaming Files

Maybe....

If your file names are 3 parts each separated by a space:
John Smith 12022005.xls

Something like this might work:

Option Explicit
Sub testme01()

Dim wkbk As Workbook
Dim myFileNames As Variant
Dim NewFileName As String
Dim iCtr As Long
Dim lCtr As Long
Dim myName As String
Dim myPath As String
Dim mySplit As Variant
Dim myExtension As String
Dim resp As Long

myFileNames = Application.GetOpenFilename("Excel Files, *.xls", _
MultiSelect:=True)

If IsArray(myFileNames) = False Then
Exit Sub
End If

For iCtr = LBound(myFileNames) To UBound(myFileNames)
'strip off .txt, .xls, .xxx
myExtension = Right(myFileNames(iCtr), 4)
myName = Left(myFileNames(iCtr), Len(myFileNames(iCtr)) - 4)

'strip off the path
For lCtr = Len(myName) To 1 Step -1
If Mid(myName, lCtr, 1) = "\" Then
'stop here
myPath = Left(myName, Len(myName) - lCtr)
myName = Mid(myName, Len(myPath) + 1)
Exit For
End If
Next lCtr

'split it into pieces
mySplit = Split97(myName, " ")
If UBound(mySplit) - LBound(mySplit) < 2 Then
'skip this one, it's not 3 pieces
Else
'first last date
'becomes
'last first date
myName = mySplit(LBound(mySplit) + 1) & " " _
& mySplit(LBound(mySplit)) & " " _
& mySplit(UBound(mySplit)) & myExtension

resp = MsgBox(Prompt:="Rename: " & myFileNames(iCtr) & vbLf _
& " To: " & myPath & myName, Buttons:=vbYesNo)
If resp = vbNo Then
'do nothing
Else
Name myFileNames(iCtr) As myPath & myName
End If
End If

Next iCtr

End Sub

Function Split97(sStr As String, sdelim As String) As Variant
'from Tom Ogilvy
Split97 = Evaluate("{""" & _
Application.Substitute(sStr, sdelim, """,""") & """}")
End Function


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Bear wrote:

I have a great number of files labeled with a first name followed by a
last name and a date. I need to switch the file names and save them as
Last Name First Name followed by the date? Any suggestion on how to do
this?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
Bear
 
Posts: n/a
Default Renaming Files

Blank spaces for example John Doe Nov05

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
Temp files causing performance degradation FrankB Excel Discussion (Misc queries) 4 October 31st 05 11:19 PM
Graphs in Other Files do not Update Dolphinv4 Excel Discussion (Misc queries) 0 October 21st 05 10:38 AM
Recently Used File List - 2002 Contains 'Temp' Files Keith972002 Excel Discussion (Misc queries) 0 July 26th 05 01:46 PM
merging my excel files Donna YaWanna Excel Discussion (Misc queries) 1 June 14th 05 12:53 AM
Cannot access read-only documents. tomgillane Excel Discussion (Misc queries) 14 February 7th 05 10:53 PM


All times are GMT +1. The time now is 08:56 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"