Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

VBA Excel: rename files

Hello experts,

I have the following procedure which allows me to rename files.

Sub Rename_Files()
'Updateby20141124
Dim xDir As String
Dim xFile As String
Dim xRow As Long
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
If .Show = -1 Then
xDir = .SelectedItems(1)
xFile = Dir(xDir & Application.PathSeparator & "*")
Do Until xFile = ""
xRow = 0
On Error Resume Next
xRow = Application.Match(xFile, Range("A:A"), 0)
If xRow > 0 Then
Name xDir & Application.PathSeparator & xFile As _
xDir & Application.PathSeparator & Cells(xRow, "B").Value
End If
xFile = Dir
Loop
End If
End With
End Sub

Open in new window


I would like to add a msgbox vbyes & vbyes at the beginning of the procedure with the following message:
"Before running this procedure, please check that old_files_names are reported in column A and new_files_names are reported in column B. If so, please click on Yes else click on No and run List Files procedure in order to get files to rename."

If you have questions, please contact me.
Regards,
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Luis Diaz

ASKER

Tested and it works!
Thank you very much for your prompt answer!
You're welcome! Glad it worked as desired.
Thanks for the feedback.