Use this bit of code to get the list of jpg files in the folder, then that part of the error would be eliminated.
Sub GetJPG()
Dim y As Long
Columns(2).ClearContents
Range("B1") = "JPG Files"
Application.ScreenUpdating = False
With Application.FileSearch
.LookIn = "C:\Documents and Settings\valued customer\My Documents\My Pictures\" 'Change to your location
.FileType = msoFileTypeAllFiles
For y = 1 To .FoundFiles.Count
Sheet1.Cells(y + 1, 2) = Mid$(.FoundFiles(y), InStrRev(.FoundFiles(y), "\") + 1)
Next
End With
OnlyJPG
End Sub
Sub OnlyJPG()
'Filters just jpg files
Dim Rws As Long, Rng As Range
Rws = Cells(Rows.Count, "B").End(xlUp).Row
Set Rng = Range(Cells(2, 2), Cells(Rws, 2))
Rng.AutoFilter Field:=1, Criteria1:="<>*.JPG*", Operator:=xlAnd
Rng.SpecialCells(xlCellTypeVisible).EntireRow.Delete
End Sub
.JPG will still remain in the file name so that part of your original code would not be required.
Bookmarks