Dazzawm
Well-known Member
- Joined
- Jan 24, 2011
- Messages
- 3,786
- Office Version
- 365
- Platform
- Windows
I found the code below on the internet which lists the names of photos when I enter the folder path. It automatically puts the results in row 1 but I want the results starting in row 2. Can anyone help please?
Code:
Sub ListPhotoNames()
'Declare variables
Dim fso As Object
Dim folderPath As String
Dim fileName As Object
Dim i As Long
'Get the folder path
folderPath = InputBox("Enter the folder path:")
'Create a FileSystemObject
Set fso = CreateObject("Scripting.FileSystemObject")
'Get the list of files in the folder
For Each fileName In fso.GetFolder(folderPath).Files
'Check if the file is a photo
If InStr(1, fileName, ".jpg") + InStr(1, fileName, ".png") + InStr(1, fileName, ".jpeg") > 0 Then
'Add the file name to the Excel sheet
i = i + 1
Cells(i, 1).Value = fileName
End If
Next fileName
End Sub