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.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I have tried the code and works well .. I have changed Z to C as I have no Z drive
VBA Code:
Private Sub CommandButton1_Click()
    Dim part As String, oldFolderName As String, newFolderName As String, rowSelect As Long

    If Me.ComboBox1.Value = "" Then
        MsgBox "Part# Can Not Be Blank!", vbExclamation, "Part#"
        Exit Sub
    End If

    part = ComboBox1.Value

    Application.ScreenUpdating = False
        rowSelect = Me.ComboBox1.ListIndex + 1
        Sheets("Data").Select
        Cells(rowSelect, 15) = Me.TextBox2.Value
    
        oldFolderName = "C:\TWE\Project\Folders" & part
        newFolderName = "C:\TWE\Project\Folders" & part & "-Done"
    
        Name oldFolderName As newFolderName
    Application.ScreenUpdating = True
End Sub

I have fixed the variable part# as this is string variable not double (or declare it as double if this suits you)
 
Upvote 0
I have tried the code and works well .. I have changed Z to C as I have no Z drive
VBA Code:
Private Sub CommandButton1_Click()
    Dim part As String, oldFolderName As String, newFolderName As String, rowSelect As Long

    If Me.ComboBox1.Value = "" Then
        MsgBox "Part# Can Not Be Blank!", vbExclamation, "Part#"
        Exit Sub
    End If

    part = ComboBox1.Value

    Application.ScreenUpdating = False
        rowSelect = Me.ComboBox1.ListIndex + 1
        Sheets("Data").Select
        Cells(rowSelect, 15) = Me.TextBox2.Value
   
        oldFolderName = "C:\TWE\Project\Folders" & part
        newFolderName = "C:\TWE\Project\Folders" & part & "-Done"
   
        Name oldFolderName As newFolderName
    Application.ScreenUpdating = True
End Sub

I have fixed the variable part# as this is string variable not double (or declare it as double if this suits you)
I have tried your code and it gives me the same error. Run time error 53' file not found. I have checked and the folder exist and a pdf file with the same name exist inside. The error keeps highlighting me this line ---> Name oldFolderName As newFolderName would it be possible that I have some property deactivated? I do not know what to try to make it work
 
Upvote 0
Is "Part" a subfolder inside "Z:\TWE\Project\Folders"?
 
Upvote 0
Is "Part" a subfolder inside "Z:\TWE\Project\Folders"?
Part is the variable name of the folder that depends on combobox1. For example PRO-001, PRO-002, etc. It is a sequential number that increases by 1 everytime an entry is created. The name of the folder is varies. In this case the folder already exist but I want to rename it as PRO-001-Done after I finish all my process.
 
Upvote 0
What is the exact path of that folder?
 
Upvote 0
C:\TWE\Project\Folders And inside folders is the folder that is created by the sequential numbers PRO-001, 002, etc
 
Upvote 0
Can you please show the exact path for the folder you are trying to rename
 
Upvote 0
Can you please show the exact path for the folder you are trying to rename
The exact path is this Z:\TWE\Project\Folders
The folder is inside the folder "Folders" in that path. Inside "Folders" there are more subfolders.
 
Upvote 0

Forum statistics

Threads
1,214,524
Messages
6,120,049
Members
448,940
Latest member
mdusw

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