Error to rename folder using Name property

YingFa

Board Regular
Joined
Nov 4, 2019
Messages
63
Hello, I have the below code to rename an existing folder but it gives me error '53 file not found when I run it. When I debug, it highlights me this line ----> Name OldFolderName As NewFolderName. Inside the existing folder is a PDF file that I do not need to change the name. I just need to change or rename the existing folder but it keeps giving me error. Can I please have your help?

I av ethe following

VBA Code:
Private Sub CommandButton1_Click()

'Update Folder Name
If Me.ComboBox1.Value = "" Then
MsgBox "Part# can Not be Blank!", vbExclamation, "Part#"
Exit Sub
End If

Dim Part# As String
Part# = ComboBox1.Value
Dim OldFolderName As String, NewFolderName As String
Dim rowselect As Long

Application.ScreenUpdating = False
rowselect = Me.ComboBox1.ListIndex + 1
Sheets("Data").Select
Cells(rowselect, 15) = Me.TextBox2.Value

OldFolderName = "Z:\TWE\Project\Folders" & Part#
NewFolderName = "Z:\TWE\Project\Folders" & Part# & "-Done"

Name OldFolderName As NewFolderName

Application.ScreenUpdating = True
    
End Sub

Thank you.
 
I think I fixed it by adding on error resume next, the folder is being renamed and not error showing. I tried almost everything and by adding that line it worked although I am not 100% sure it is ok to use on error resume next.

Private Sub CommandButton1_Click()

'Update Folder Name
If Me.ComboBox1.Value = "" Then
MsgBox "Part# can Not be Blank!", vbExclamation, "Part#"
Exit Sub
End If

Dim Part# As String
Part# = ComboBox1.Value
Dim OldFolderName As String, NewFolderName As String
Dim rowselect As Long

Application.ScreenUpdating = False

On Error Resume Next
rowselect = Me.ComboBox1.ListIndex + 1
Sheets("Data").Select
Cells(rowselect, 15) = Me.TextBox2.Value

OldFolderName = "Z:\TWE\Project\Folders" & Part#
NewFolderName = "Z:\TWE\Project\Folders" & Part# & "-Done"

Name OldFolderName As NewFolderName

Unload Me

MsgBox Part# & " has been closed"
Application.ScreenUpdating = True

End Sub
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
If Part is a subfolder of folders, then you are missing a \ here
Rich (BB code):
"Z:\TWE\Project\Folders\" & Part#
 
Upvote 0

Forum statistics

Threads
1,214,810
Messages
6,121,690
Members
449,048
Latest member
81jamesacct

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