Error in code to rename existing folder

SSF1590

Board Regular
Joined
Oct 20, 2019
Messages
73
Hello,

I have the following code to rename an existing folder but it gives me error in the line: OldFolderName As NewFolderName. Can I please have your help to make it work?
Thank you.

Code:
Private Sub CommandButton1_Click()


If Me.ComboBox1.Value = "" Then
MsgBox "CAR can Not be Blank!", vbExclamation, "CAR"


Dim OldFolderName As String, NewFolderName As String
Dim CAR As String
CAR = ComboBox1.Text


'Set Folder Names
    OldFolderName = "Z:\Document\Department\CAR Project\CAR Folders\" & CAR
    NewFolderName = ""Z:\Document\Department\CAR Project\CAR Folders\"" & CAR & "-Closed"
    
'Rename them
   OldFolderName As NewFolderName
   
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
You'll need to use the Name statement..

Code:
Name OldFolderName As NewFolderName
 
Upvote 0
Sorry, I actually have that in my code but it is giving me run time error '53': File not found. The thing is that inside the folder I have a pdf file with the same name of the folder. The folder is changing to the new name but it gives me error everytime and I do not know how to avoid this. Everytime I debug it chighlights this line Name OldFolderName As NewFolderName. What do you think I am doing wrong?
This is my actual code

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False

If Me.ComboBox1.Value = "" Then
MsgBox "CAR can Not be Blank!", vbExclamation, "CAR"


Dim OldFolderName As String, NewFolderName As String
Dim CAR As String
CAR = ComboBox1.Text


'Set Folder Names
OldFolderName = "Z:\Document\Department\CAR Project\CAR Folders" & CAR
Name NewFolderName = ""Z:\Document\Department\CAR Project\CAR Folders"" & CAR & "-Closed"

'Rename them
OldFolderName As NewFolderName

Application.ScreenUpdating = True
End Sub
 
Upvote 0
It should be as follows...

Code:
[COLOR=#333333]'Set Folder Names[/COLOR]
[COLOR=#333333]OldFolderName = "Z:\Document\Department\CAR Project\CAR Folders" & CAR[/COLOR]
[COLOR=#333333]NewFolderName = "Z:\Document\Department\CAR Project\CAR Folders" & CAR & "-Closed"[/COLOR]

[COLOR=#333333]'Rename them[/COLOR]
[COLOR=#333333]Name OldFolderName As NewFolderName[/COLOR]
 
Last edited:
Upvote 0
I have that code and it keeps giving me error 53, not file found, but the folder exists. Inside this folder there is a pdf file. When I debug line Name OldFolderName As NewFolderName is highlighted. When I place the cursor one the Name property after debugging, the name says "UserForm3. Do you know why is giving me this error?
 
Upvote 0
I have that code and it keeps giving me error 53, not file found, but the folder exists...

You in fact do not have that code. You have the following...

Code:
[COLOR=#333333]'Set Folder Names[/COLOR]
[COLOR=#333333]OldFolderName = "Z:\Document\Department\CAR Project\CAR Folders" & CAR[/COLOR]
[COLOR=#333333]Name NewFolderName = ""Z:\Document\Department\CAR Project\CAR Folders"" & CAR & "-Closed"[/COLOR]

[COLOR=#333333]'Rename them[/COLOR]
[COLOR=#333333]OldFolderName As NewFolderName[/COLOR]

..which is incorrect. This differs from the code that I posted. Also, if "CAR Folders" is a sub-folder, you'll need to add a backslash as follows...

Code:
[COLOR=#333333]'Set Folder Names
[/COLOR][COLOR=#333333]OldFolderName = "Z:\Document\Department\CAR Project\CAR Folders[/COLOR][COLOR=#ff0000]\[/COLOR][COLOR=#333333]" & CAR
[/COLOR][COLOR=#333333]NewFolderName = "Z:\Document\Department\CAR Project\CAR Folders[/COLOR][COLOR=#ff0000]\[/COLOR][COLOR=#333333]" & CAR & "-Closed"[/COLOR]
 
Upvote 0
Thank you fro your reply. What I mean to say is I already corrected my code adding the backslash as your above code. This is what I have in my code right now and it stills give me error 53. I still cannot figure it out. is it working for you?

OldFolderName = "Z:\Document\Department\CAR Project\CAR Folders\" & CAR
NewFolderName = "Z:\Document\Department\CAR Project\CAR Folders" & CAR & "-Closed"
 
Upvote 0
I have corrected my code and it still gives me error 53. The below is what I have as code. It looks like the code is ok, but it is just not running. I do not know what else is wrong.

'Set Folder Names
OldFolderName = "Z:\Document\Department\CAR Project\CAR Folders" & CAR
NewFolderName = "Z:\Document\Department\CAR Project\CAR Folders" & CAR & "-Closed"

'Rename them
Name OldFolderName As NewFolderName
 
Upvote 0
In Post #7 , you added a backslash for OldFolderName, but not NewFolderName. Then, in your next post, you removed the backslash from OldFolderName. Shouldn't they both have backslahes? What should the path and folder name be for both, and what value does CAR hold?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,098
Messages
6,170,103
Members
452,302
Latest member
TaMere

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