Remove Photos From One Folder To Another Using VBA

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,748
Office Version
  1. 365
Platform
  1. Windows
I have a folder with thousands of photos, I believe it is possible to move them to another folder according to a list in column A of a spreadsheet using VBA. Any ideas how to please?
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Re: "list in column A"
What is in this list? Existing names I assume. What about the path?
 
Upvote 0
Change references as required. Both assume header in row 1

If you have only the picture name incl extension in Column A and the paths are as indicated.
VBA Code:
Sub Maybe_So()
Dim pathOld As String, pathNew As String, c As Range
pathOld = "C:\AAAAAA\"    '<---- Folder where the pictures to be moved are in.
pathNew = "C:\AAAAAA\AAA\"    '<---- Folder where the pictures should be moved to.
    For Each c In Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)
        Name pathOld & c.Value As pathNew & c.Value
    Next c
End Sub


If you have the Picture names including path and extension in Cells in Column A (Like "C:\Folder 1\Folder 2\Nice Photo.jpg")
Code:
Sub Maybe_So_With_Path()
Dim pathNew As String, c As Range
pathNew = "C:\AAAAAA\AAA\"    '<---- Folder where the pictures should be moved to.
    For Each c In Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)
        Name c.Value As pathNew & Mid(c.Value, InStrRev(c.Value, "\") + 1)
    Next c
End Sub
 
Upvote 0
Sub Maybe_So() Dim pathOld As String, pathNew As String, c As Range pathOld = "C:\AAAAAA\" '<---- Folder where the pictures to be moved are in. pathNew = "C:\AAAAAA\AAA\" '<---- Folder where the pictures should be moved to. For Each c In Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row) Name pathOld & c.Value As pathNew & c.Value Next c End Sub
Thanks. I had a debug and it pointed to this line.

Name pathOld & c.Value As pathNew & c.Value
 
Upvote 0
Someone please help!! I need it asap for work!!
 
Upvote 0
Panic over, I found this on the internet if it helps anyone else.

Code:
Sub movefiles()
'Updateby Extendoffice
    Dim xRg As Range, xCell As Range
    Dim xSFileDlg As FileDialog, xDFileDlg As FileDialog
    Dim xSPathStr As Variant, xDPathStr As Variant
    Dim xVal As String
    On Error Resume Next
    Set xRg = Application.InputBox("Please select the file names:", "KuTools For Excel", ActiveWindow.RangeSelection.Address, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    Set xSFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
    xSFileDlg.Title = " Please select the original folder:"
    If xSFileDlg.Show <> -1 Then Exit Sub
    xSPathStr = xSFileDlg.SelectedItems.Item(1) & "\"
    Set xDFileDlg = Application.FileDialog(msoFileDialogFolderPicker)
    xDFileDlg.Title = " Please select the destination folder:"
    If xDFileDlg.Show <> -1 Then Exit Sub
    xDPathStr = xDFileDlg.SelectedItems.Item(1) & "\"
    For Each xCell In xRg
        xVal = xCell.Value
        If TypeName(xVal) = "String" And xVal <> "" Then
            FileCopy xSPathStr & xVal, xDPathStr & xVal
            Kill xSPathStr & xVal
        End If
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,378
Messages
6,124,603
Members
449,174
Latest member
ExcelfromGermany

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