Luis Diaz
asked on
Excel VBA: rename folders based on columns
Hello Experts,
I have the following procedure which allows me to rename folders:
I would like to properly manage errors such as:
1-If folder reported in column A doesn’t exist skip the cell, display msbgox “Folder cannot renamed as it doesn’t exist” and continue with the next cell
2-If target folder reported in column B cannot be renamed, display msgbox “Folder cannot be renamed”
Please find attached example file.
If you have questions, please contact me.
Rename-folders-based-on-columns.xlsm
I have the following procedure which allows me to rename folders:
Sub Rename_Folders()
Const FILEPATH As String = "C:\"
Dim strfile As String
Dim filenum As String
strfile = Dir(FILEPATH)
Dim lr As Long
Dim ws As Worksheet
Dim old_name, new_name As String
Set ws = ActiveSheet
lr = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For i = 2 To lr
''strOldDirName = FILEPATH & Sheets(1).Cells(i, 1).Value
''strNewDirName = FILEPATH & Sheets(1).Cells(i, 3).Value
strOldDirName = ws.Cells(i, "A").Value
strNewDirName = ws.Cells(i, "B").Value
Name strOldDirName As strNewDirName
Next i
End Sub
I would like to properly manage errors such as:
1-If folder reported in column A doesn’t exist skip the cell, display msbgox “Folder cannot renamed as it doesn’t exist” and continue with the next cell
2-If target folder reported in column B cannot be renamed, display msgbox “Folder cannot be renamed”
Please find attached example file.
If you have questions, please contact me.
Rename-folders-based-on-columns.xlsm
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER