sort pdf files in folder A-Z

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,720
Office Version
  1. 2007
Platform
  1. Windows
Morning.
I have a command button on my worksheet which opens folder folder on my pc for which i keep pdf files.
The files keep changing to smallest number to largest number 1,2,3,4 etc

I have the following code which opens the folder BUT can i add to the code so it sorts the pdf files so i see 4,3,2,1 order.

Thanks.

Rich (BB code):
Private Sub CustomerSortAtoZ_Click()
    Dim x As Long
        Application.ScreenUpdating = False
        With Sheets("DATABASE")
        If .AutoFilterMode Then .AutoFilterMode = False
        x = .Cells(.Rows.Count, 1).End(xlUp).Row
            .Range("A5:Z" & x).Sort Key1:=Range("A6"), Order1:=xlAscending, Header:=xlGuess
    End With
    ActiveWorkbook.Save
       Application.ScreenUpdating = True
    MsgBox "SORTED A-Z SUCCESSFULLY", vbInformation, "DATABASE SORT A-Z MESSAGE"
       
       Sheets("DATABASE").Range("A7").Select
       Sheets("DATABASE").Range("A6").Select
       
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Would changing to =xlDescending be of some help ?
VBA Code:
.Range("A5:Z" & x).Sort Key1:=Range("A6"), Order1:=xlDescending, Header:=xlGuess
 
Upvote 0
Im sorry i supplied the wrong code in post #1

The code i use to open the folder is shown below.

Rich (BB code):
Private Sub OpenPdf_Click()
Dim strFolder As String
strFolder = "C:\Users\Ian\Desktop\REMOTES ETC\DR\DR SCREEN SHOT PDF\"
ActiveWorkbook.FollowHyperlink Address:=strFolder, NewWindow:=True
End Sub

Now once the folder is open i would like to sort the files from highest number to lowets number 100,99,98,97,96 etc

Many thanks
 
Upvote 0
Sorry, no idea how this can be done since folders are sorted by default in Windows explorer pane; maybe with use of some API but the easiest is to click on the header of the filename column in Windows explorer. Other solution could be to import the list of files and have Excel do the sorting then paste them into a userform and from it manage them as needed but this is a different approach.
 
Upvote 0

Forum statistics

Threads
1,223,635
Messages
6,173,479
Members
452,516
Latest member
archcalx

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