ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Renaming files in a directory (https://www.excelbanter.com/excel-programming/347543-renaming-files-directory.html)

Candyman

Renaming files in a directory
 
How do I rename the files in a directory? I have many reports in directory I
can loop through each file but how do i rename it? I have an input box to
assign a NewFileName. I want to keep the date suffix and change the first
part of the filename. This jams in the last line attempts. Please help. I
feel like i'm shooting inthe dark now.

If Right(myName, 3) = "xls" Then
OldFileName = myPath & myName
NameDate = Right(myName, 12)
NewFileName = (myPath & NewName & " " & NameDate)
Workbooks(OldFileName).SaveAs (NewFileName)
'Workbooks(OldFileName).Name = (NewFileName)

TIA
Candyman

jgeniti

Renaming files in a directory
 
As long as you're not trying to rename the file that you are currently
working on you can use the Name function.

Name OldFileName as NewFileName

This way you don't have to use "SaveAs"


Candyman

Renaming files in a directory
 
Thats it! YES!!!
Thanks :)

"JGeniti" wrote:

As long as you're not trying to rename the file that you are currently
working on you can use the Name function.

Name OldFileName as NewFileName

This way you don't have to use "SaveAs"




All times are GMT +1. The time now is 10:03 AM.

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