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.
 

Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

YasserKhalil

Well-known Member
Joined
Jun 24, 2010
Messages
815
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)
 

YingFa

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

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,529
Office Version
  1. 365
Platform
  1. Windows
Is "Part" a subfolder inside "Z:\TWE\Project\Folders"?
 

YingFa

Board Regular
Joined
Nov 4, 2019
Messages
63

ADVERTISEMENT

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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,529
Office Version
  1. 365
Platform
  1. Windows
What is the exact path of that folder?
 

YingFa

Board Regular
Joined
Nov 4, 2019
Messages
63

ADVERTISEMENT

C:\TWE\Project\Folders And inside folders is the folder that is created by the sequential numbers PRO-001, 002, etc
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,529
Office Version
  1. 365
Platform
  1. Windows
Can you please show the exact path for the folder you are trying to rename
 

YingFa

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

YingFa

Board Regular
Joined
Nov 4, 2019
Messages
63
Basically the folder that I want to rename is a subfolder of Folders.
 

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