0

I have to import images to an array and then insert these images to excel worksheet.

I have a code which gets the name of all files into an array and insert one by one. but the order is jumbled. I used Dir() method

Do While sFile <> ""
    aFileNames(nCounter) = sFile
    sFile = Dir
    nCounter = nCounter + 1

    If nCounter > UBound(aFileNames) Then
        ReDim Preserve aFileNames(UBound(aFileNames) + 255)
    End If

Loop

I need to get the array of file names in date modified (ascending).so that first image which was first saved will be inserted first

braX
  • 11,506
  • 5
  • 20
  • 33
Ash Sooraj
  • 55
  • 9
  • Use a filesystem object to get the date for each file, and add them both to a scripting dictionary, then convert that to an array, and then sort the array. – braX Oct 28 '19 at 17:08
  • thanks for you answer.i am new to file system object , can you help me with that. – Ash Sooraj Oct 28 '19 at 17:10
  • 1
    https://stackoverflow.com/questions/16627441/excel-vba-using-filesystemobject-to-list-file-last-date-modified – braX Oct 28 '19 at 17:11
  • But will it work if all the images are saved at almost same time??(they all will be having same date and time) – Ash Sooraj Oct 28 '19 at 20:53
  • They couldnt possibly be all saved at the exact same second, right? The File Information date/time has the information down to the second for you to utilize. – braX Oct 29 '19 at 00:56
  • Ok will try it .thanks for the help – Ash Sooraj Oct 29 '19 at 05:10
  • Hello brax ,all the images gets saved on a single click and in matter of seconds.so there will be multiple image with same time(including seconds).it sorts perfectly when i sort in folder – Ash Sooraj Oct 29 '19 at 18:52

0 Answers0