Macro to rename Excel files in a folder

C

cfatz1

Hi-

I have a folder with 500 or so Excel files and they all start with a
specific date. For Example: 20070119_File1.xls

Does anyone have a macro that will loop through the folder and rename
just the date portion of the file? Example: I want to rename all of
the files that start with 20070119 to start with 20061231 but still
contain the rest of the filename.

Take:

20070119_File1.xls

and rename it:

20061231_File1.xls

Any help is appreciated!

Thanks,
Chris
 
D

Don Guillett

You could modify this to work within a DIR loop using mid oldname and mid
newname

Sub movefile()
OldName = "C:\oldfolderl\oldname.xls"
NewName = "C:\newfolder\newname.xls"
Name OldName As NewName
End Sub
Sub anotherfindfiles1() 'It does work.
Application.ScreenUpdating = False
Dim FN As String ' For File Name
FileLocation = "c:\a\*.xls"
FN = Dir(FileLocation)
Do Until Left(FN, 3) = "Don"

rename in here

FN = Dir
Loop
Application.ScreenUpdating = True
End Sub
 
C

cfatz1

Thanks Don. Appreciate the help.

Chris

Don said:
You could modify this to work within a DIR loop using mid oldname and mid
newname

Sub movefile()
OldName = "C:\oldfolderl\oldname.xls"
NewName = "C:\newfolder\newname.xls"
Name OldName As NewName
End Sub
Sub anotherfindfiles1() 'It does work.
Application.ScreenUpdating = False
Dim FN As String ' For File Name
FileLocation = "c:\a\*.xls"
FN = Dir(FileLocation)
Do Until Left(FN, 3) = "Don"

rename in here

FN = Dir
Loop
Application.ScreenUpdating = True
End Sub
 
D

Don Guillett

Post back if you need further help and pls post your final result for the
benefit of all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top