Jagdev Singh
Active Member
Hi Experts
I have the below code with rename the PDF files within the folder via excel cell value. The first code runs and list all the PDF names available in column A and what ever I add in column B will get renamed the old files. It works fine few of the times, but throw error file not available on the following code.
Entire code
Error code
Name Cells(r,"A") As Cells(r,"B")
Error - run-time error '53' file not found
Regards,
JD
I have the below code with rename the PDF files within the folder via excel cell value. The first code runs and list all the PDF names available in column A and what ever I add in column B will get renamed the old files. It works fine few of the times, but throw error file not available on the following code.
Entire code
Code:
Sub ListFiles()
Dim MyFolder As String
Dim MyFile As String
Dim j As Integer
MyFolder = "C:\DealerExam"
MyFile = Dir(MyFolder & "\*.*")
a = 0
Do While MyFile <> ""
a = a + 1
Cells(a, 1).Value = MyFile
MyFile = Dir
Loop
End Sub
Sub ReName_Files()
ChDrive "C:" ' <-- Change to your folder drive
ChDir "C:\DealerExam\" ' <-- Change to your folder
Dim r As Integer
r = 1
Do Until IsEmpty(Cells(r, "A")) Or IsEmpty(Cells(r, "B"))
Name Cells(r, "A") As Cells(r, "B")
r = r + 1
Loop
MsgBox "All your old file names in Column 'A' have been reNamed" & vbCr & _
"to the adjacent new name in column 'B'."
End Sub
Error code
Name Cells(r,"A") As Cells(r,"B")
Error - run-time error '53' file not found
Regards,
JD
Last edited: