Amit,
If you want the output to be 5 random files instead of all of them, you can use the following:
Sub BuildListOf_Files_to_Upload()
Const strExt As String = "*.jpg"
Dim strFldr As String: strFldr = Range("C8").Text & "\" '"C:\images folder"
Dim fName As String: fName = Dir(strFldr & strExt)
Dim arrFiles() As String
Dim arrIndex As Long, arrChk As Long
Dim arrRandFiles(1 To 5) As String
While fName <> vbNullString
arrIndex = arrIndex + 1
ReDim Preserve arrFiles(1 To arrIndex)
arrFiles(arrIndex) = fName
fName = Dir
Wend
Randomize
For arrIndex = 1 To 5
arrRandFiles(arrIndex) = arrFiles(WorksheetFunction.RandBetween(1, UBound(arrFiles)))
For arrChk = 1 To arrIndex - 1
If arrRandFiles(arrChk) = arrRandFiles(arrIndex) Then arrIndex = arrIndex - 1
Next arrChk
Next arrIndex
Range("N1").Resize(5).Value = WorksheetFunction.Transpose(arrRandFiles)
End Sub
Bookmarks