Slight Amendment To Code

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,786
Office Version
  1. 365
Platform
  1. 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
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Put a new line just below the last 'Dim' line
VBA Code:
i = 1
 
Upvote 1
Solution

Forum statistics

Threads
1,224,812
Messages
6,181,091
Members
453,021
Latest member
Justyna P

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