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
 

Some videos you may like

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
36,067
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\"
 

Watch MrExcel Video

Forum statistics

Threads
1,122,553
Messages
5,596,807
Members
414,104
Latest member
imamalidadashzada

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