PDA

View Full Version : Solved: Rename the name of files



parscon
04-24-2013, 05:26 AM
I have a folder with 1800 files and also i have the list of their name and also i want to change the name of them to new name .(also i have the ne name list)

I write this VBA but this code just rename 1 item how can i add other item to my list ?

Thank you .


Sub Rename()
Dim FileName As String
Dim NewFileName As String
On Error Resume Next
FileName = "E:\1.jpg"
NewFileName = "E:\apple-A43.jpg"
Name FileName As NewFileName
End Sub

parscon
04-24-2013, 05:39 AM
I found it . thanks Xld



Sub RenameFiles()
Dim FilesDir As String
Dim CurFile As String
Dim RowNum As Long

With Application.FileDialog(msoFileDialogFolderPicker)

.AllowMultiSelect = False
If .Show = -1 Then

FilesDir = .SelectedItems(1)
CurFile = Dir(FilesDir & Application.PathSeparator & "*")
Do Until CurFile = ""

RowNum = 0
On Error Resume Next
RowNum = Application.Match(CurFile, Range("A:A"), 0)
On Error Goto 0
If RowNum > 0 Then

Name FilesDir & Application.PathSeparator & CurFile As _
FilesDir & Application.PathSeparator & Cells(RowNum, "B").Value
End If
CurFile = Dir
Loop
End If
End With
End Sub