• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Rename image files

jduane

New Member
I am looking for a way to rename image files. I used the embedded VBA Macro twice successfully, but all of a sudden it stopped working.

I was wondering what was wrong and if there was a better, less temperamental solution to doing this. The whole premise was to create a loop where every image name in column A would be renamed to the corresponding value in column B. I have attached my workbook I have been using as well.

Code:
Sub Macro2()
'
' Macro2 Macro
'




z = 1
For z = 1 To 1057



Name "F:\RetailSource\Images\Folder 1\" & Range("a" & z).Value & ".jpg" As "F:\RetailSource\Images\Folder 2\" & Range("b" & z).Value & ".jpg"

Next z
'
End Sub
 

Attachments

  • Rename Files.xlsm
    38 KB · Views: 4
A few comments

1. There are only 1020 lines in the file so the line should say:
For Z = 1 To 1020 'Not 1057

2. The file cannot exist in the new folder Folder 2

3. The file must exist in the existing folder Folder 1

4. Cell A1 is a Number, whereas all other cells in Column A & B are Text

I would make them all Numbers using Text to Column
Then adjust the VBA line for this using:

Name "F:\RetailSource\Images\Folder 1\" & Range("a" & Z).Text & ".jpg" As "F:\RetailSource\Images\Folder 2\" & Range("b" & Z).Text & ".jpg"

5. Because Folder 2 <> Folder 1 it is moving the files, is that what you wanted to do?
 
Hui,

I tried what you said and the Macro was still unsuccessful. Yes, I do want to move the renamed images from one folder to the next. I attached the file with the changes you specified so you can take another look at it.

Also, I took your 4th comment to mean, change format of all of the cells to numbers. So that's what I did. If all of the cells are numbers then is the .Text really the appropriate extension? Or is it unrelated to the format of the cells. Please see attached.
 

Attachments

  • Rename Files.xlsm
    33.4 KB · Views: 6
Back
Top