Renaming images and moving to a new folde VBA

murrayjl03

New Member
Joined
Apr 23, 2015
Messages
5
Hi there,

I hope you can help me, I have found similar scenarios but nothing that fits my needs and I'm too new to VBA to work it out.

I have thousands of images currently in random folders fom my suppliers. I am wanting to rename all these images and then move to another folder in a different location.

Ideally I would create an excel like this;
Original image locationSKUImage renamed toAdd to location
C:folder1SKU123456Size12-Large-Mens-HoodieC:newfolder1
C:folder2SKU567890Size12-Large-Mens-Hoodie-RedC:newfolder2

Step 1 would be to rename the images. Within folder 1, there will be around 25 images so i would want iterations of the renaming to be "Size12-Large-Mens-Hoodie-1", "Size12-Large-Mens-Hoodie-2" etc. Ideally, it would do it in order, so the first image in the folder would become '1'.

Apart from that, I would create all of the details in the table above.

If anyone can help me out, it would seriously be appriciated.

Thanks,

Jess
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
This macro renames each folder's files and moves them to the new folder in one step. Test it on just one sheet row by deleting row 3 in your example.

VBA Code:
Public Sub Rename_and_Move_Files()

    Dim sourceFolder As String, destFolder As String, fileName As String
    Dim r As Long, n As Long, p As Long
    
    With ActiveSheet
        For r = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
            sourceFolder = .Cells(r, "A").Value
            If Right(sourceFolder, 1) <> "\" Then sourceFolder = sourceFolder & "\"
            destFolder = .Cells(r, "D").Value
            If Right(destFolder, 1) <> "\" Then destFolder = destFolder & "\"
            n = 0
            fileName = Dir(sourceFolder & "*.*")
            While fileName <> vbNullString
                n = n + 1
                p = InStrRev(fileName, ".")
                Name sourceFolder & fileName As destFolder & .Cells(r, "C").Value & "-" & n & Mid(fileName, p)
                fileName = Dir
            Wend
        Next
    End With
    
    MsgBox "Done"
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,096
Messages
6,123,074
Members
449,094
Latest member
mystic19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top