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.
 

YingFa

Board Regular
Joined
Nov 4, 2019
Messages
63
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
 

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,529
Office Version
  1. 365
Platform
  1. Windows
If Part is a subfolder of folders, then you are missing a \ here
Rich (BB code):
"Z:\TWE\Project\Folders\" & Part#
 

Watch MrExcel Video

Forum statistics

Threads
1,127,554
Messages
5,625,474
Members
416,109
Latest member
TripleA00123

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
Top