Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-03-2023, 02:34 AM
Priyantha Gamini Priyantha Gamini is offline Sorting File names Windows 10 Sorting File names Office 2016
Novice
Sorting File names
 
Join Date: Dec 2022
Posts: 9
Priyantha Gamini is on a distinguished road
Default Sorting File names

Dear All,



I get file names to an excel sheet from a folder, using the below macro. I tried to sort them in ascending order. but I have not sorted them in the correct order. please can anyone solve this issue?

Correct oder : 1-1.pdf, 1-2.pdf, 1-3.pdf ............... 1-10.pdf, 1-11.pdf......1-20.pdf..

After getting to the excel sheet: 1-1.pdf, 1-10.pdf, 1-11.pdf, 1-20.pdf........

My VBA Code :

Sub Get_Old_File_Name()
Dim myPath As String
Dim myFile As String
Dim r As Long

myPath = "C:\Users\User\Desktop\Maling Payadvice\NVQ\PaySlips"
myFile = Dir(myPath & "*.*")

If myFile = "" Then
MsgBox " No Files in the Folder"
Else

r = 4

Do While myFile <> ""
Cells(r, 5).Value = myFile
r = r + 1
myFile = Dir

Loop
MsgBox "Completed"
End If
End Sub
Attached Images
File Type: jpg Correct Oder.jpg (137.8 KB, 10 views)
File Type: jpg In the Excel Sheet Oder.jpg (235.4 KB, 10 views)
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting Names LargeAllen Word 3 04-19-2017 11:42 PM
Sorting File names How capture a folder's file names to a file? BobKnepper Word 2 05-22-2016 07:30 AM
Sorting File names Copy and Paste from File to File but File Names always change aaronbauer1980 Excel Programming 1 04-15-2016 05:53 PM
Sorting File names Problem sorting names alphabetically? mikehende Excel 12 09-12-2012 12:00 PM
Two Different Names in the Same File kathy carson Outlook 0 02-14-2006 01:02 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:42 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft