Access Files No In Order

Vanda_a

Well-known Member
Joined
Oct 29, 2012
Messages
934
Hello all,

Could you please help telling why my code access file number 10 before number 02?
Code:
Sub PDFRename()
    Dim MyPath
    Dim MyFile As File
    Dim NUM As String
    Dim FSO As Object
    Dim Lrow As Long
    Dim x As Long
   
    Lrow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row
    x = 4
   
    Application.EnableCancelKey = xlInterrupt
   
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set MyPath = FSO.GetFolder("C:\Users\Vanda\DesktopRename File\")
   
    For Each MyFile In MyPath.Files
    NUM = ActiveSheet.Cells(x, 2).Text
        MyFile.Name = NUM & ".pdf"
        'MyFile.Move NexPath
        x = x + 1
 If x = Lrow Then Exit Sub
    Next

End Sub
First it worked but after my IT change some version of office or windows, it is not working now. i have a bunch of files which name start from xxx01 to xxx200.
When the code rename file number 01 then it go to nuber 10 instead of number 02. I have no idea why it is happening.

Thank you very much
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Bump.
I figured it out. Because my files name are xxx1, xxx2, xxx10. If the file name are xxx01, xxx02, xxx10. The code will works.
Anyone please kindly help.
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,746
Members
448,989
Latest member
mariah3

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