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/403253-renaming-files-directory.html)

nospaminlich

Renaming files in a directory
 
In a spreadsheet called FileList I have a list of files in Col A like this:

C:\Documents and Settings\##My Documents\My Things\Blah Blah
Blah\Folder_2\01 Filename

In Col B I have the new file names like this:

C:\Documents and Settings\##My Documents\My Things\Blah Blah
Blah\Folder_2\01 New Filename

I want to replace all the file names in Col A with the new file names in Col
B so the file name in A2 would be replaced by B2 etc.

How do I make my macro Name OldFileName as NewFileName through each row in
the 2 lists?

Any help would be much appreciated

Many thanks

Kewa




Ron de Bruin

Renaming files in a directory
 
Hi Kewa

The basic code looks like this
Maybe it is better to test if the file in A exist before you rename it ?


For Each cell In Columns("A").SpecialCells(xlCellTypeConstants)
Name cell.Value As cell.Offset(0,1).Value
Next cell



--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"nospaminlich" wrote in message ...
In a spreadsheet called FileList I have a list of files in Col A like this:

C:\Documents and Settings\##My Documents\My Things\Blah Blah
Blah\Folder_2\01 Filename

In Col B I have the new file names like this:

C:\Documents and Settings\##My Documents\My Things\Blah Blah
Blah\Folder_2\01 New Filename

I want to replace all the file names in Col A with the new file names in Col
B so the file name in A2 would be replaced by B2 etc.

How do I make my macro Name OldFileName as NewFileName through each row in
the 2 lists?

Any help would be much appreciated

Many thanks

Kewa




nospaminlich

Renaming files in a directory
 
Many thanks Ron. That works a treat.

Kewa


All times are GMT +1. The time now is 05:30 AM.

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