ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to rename Excel files in a folder (https://www.excelbanter.com/excel-programming/381516-macro-rename-excel-files-folder.html)

[email protected]

Macro to rename Excel files in a folder
 
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


Don Guillett

Macro to rename Excel files in a folder
 
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

--
Don Guillett
SalesAid Software

wrote in message
oups.com...
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




[email protected]

Macro to rename Excel files in a folder
 
Thanks Don. Appreciate the help.

Chris

Don Guillett wrote:
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

--
Don Guillett
SalesAid Software

wrote in message
oups.com...
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



Don Guillett

Macro to rename Excel files in a folder
 
Post back if you need further help and pls post your final result for the
benefit of all.

--
Don Guillett
SalesAid Software

wrote in message
oups.com...
Thanks Don. Appreciate the help.

Chris

Don Guillett wrote:
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

--
Don Guillett
SalesAid Software

wrote in message
oups.com...
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






All times are GMT +1. The time now is 01:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com