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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,045
Messages
6,122,840
Members
449,096
Latest member
Erald

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