A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi,
Sorry, the IF loop has to come out of the For Next loop. Try this
Sub ListPDFFiles()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object
Dim ws As Worksheet
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ws = ActiveSheet
Dim folderpath
folderpath = InputBox("Enter Folder Path", "Folder Path")
'Get the folder object associated with the directory
Set objFolder = objFSO.GetFolder(folderpath)
ws.Cells(1, 1).Value = "The files found in " & objFolder.Name & " are:"
'Loop through the Files collection
For Each objFile In objFolder.Files
If UCase$(Right$(objFile.Name, 4)) = ".PDF" Then
ws.Cells(ws.UsedRange.Rows.Count + 1, 1).Value = Replace$(UCase$(objFile.Name), ".PDF", "")
z=z+1
End If
Next
If z=0 then
Msgbox "No PDF Files found"
Endif
'Clean up!
Set objFolder = Nothing
Set objFile = Nothing
Set objFSO = Nothing
End Sub