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
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
Thanks. I had a debug and it pointed to this line.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
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