Sub rename_()

ExcelDennis

New Member
Joined
Aug 12, 2013
Messages
25
Hi,

I want to rename PT63MW-2012 Ocena Roczna dla Joanna Oręczuk-18159.pdf to 2570657_Perf_doc_2012_Succesfactor_1335.pdf

PT63MW-2012 Ocena Roczna dla Joanna Oręczuk-18159.pdf is in cell A1
2570657_Perf_doc_2012_Succesfactor_1335.pdf is in cell B1

File is in C\temp\

I use following VBA script

Sub rename_()
Dim OldName As String, NewName As String, mydir As String

mydir = "C:\Temp"

With Worksheets("Sheet1")
OldName = .Range("A1").Value
NewName = .Range("B1").Value
End With

Name mydir & OldName As mydir & NewName
End Sub

After running i do get Run-time error '53': File not Found. I guess because of the special Character ę in the name.

Pls help me with changing the code so i can rename the file. (need to rename over 15000 files with special characters)

Thanks
 

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.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
38,775
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2010
Platform
  1. Windows
  2. MacOS
I imagine it's just because you don't have a backslash on the end of the path. Try using:

Code:
mydir = "C:\Temp\"
 

ExcelDennis

New Member
Joined
Aug 12, 2013
Messages
25
Hi Sir,

Did changed that in the code but still same error, when I leave the special character out my script works

Do u have other suggestions

Thanks

I imagine it's just because you don't have a backslash on the end of the path. Try using:

Code:
mydir = "C:\Temp\"
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,863
Messages
5,834,051
Members
430,259
Latest member
msthiagu

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