Renaming pdf files in a folder

mzithoboss

New Member
Joined
Sep 23, 2016
Messages
5
I copied below code to rename my pdf's in a folder and got the following three errors
-Expression is not a method.
-Method arguments must be enclosed in parentheses.
-Comma, ')', or a valid expression continuation expected.
The line that is being rejected is highlighted in code

CODE///

Sub MyRenameFiles()




Dim MyFolder As String
Dim MyFile As String
Dim i As Long
Dim MyOldFile As String
Dim MyNewFile As String
Dim Name As Attribute




MyFolder = "C:\Protea"
MyFile = Dir(MyFolder & "\*.pdf")


Do While MyFile <> ""
i = i + 1
MyOldFile = MyFolder & "" & MyFile
MyNewFile = MyFolder & "" & i & ".pdf"
Name MyOldFile As MyNewFile
MyFile = Dir()
Loop
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try this

Code:
Sub MyRenameFiles()

    Dim MyFolder As String
    Dim MyFile As String
    Dim i As Long
    Dim MyOldFile As String
    Dim MyNewFile As String
    
    Sep = Application.PathSeparator
    
    
    MyFolder = "C:\Protea"
    MyFile = Dir(MyFolder & "\*.pdf")
    
    
    Do While MyFile <> ""
    i = i + 1
    MyOldFile = MyFolder & Sep & MyFile
    MyNewFile = MyFolder & Sep & i & ".pdf"
    Name MyOldFile As MyNewFile
    MyFile = Dir()
    Loop


End Sub
 
Upvote 0
Try this

Code:
Sub MyRenameFiles()

    Dim MyFolder As String
    Dim MyFile As String
    Dim i As Long
    Dim MyOldFile As String
    Dim MyNewFile As String
    
    Sep = Application.PathSeparator
    
    
    MyFolder = "C:\Protea"
    MyFile = Dir(MyFolder & "\*.pdf")
    
    
    Do While MyFile <> ""
    i = i + 1
    MyOldFile = MyFolder & Sep & MyFile
    MyNewFile = MyFolder & Sep & i & ".pdf"
    Name MyOldFile As MyNewFile
    MyFile = Dir()
    Loop


End Sub

Thank you. I used the proposed code and got this new error. The previous errors are still there.

Error 1 'PathSeparator' is not a member of 'System.Windows.Forms.Application'. C:\Users\User\AppData\Local\Temporary Projects\WindowsApplication1\Module1.vb 12 15 WindowsApplication1
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,620
Members
449,240
Latest member
lynnfromHGT

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