导出文件夹中的pdf文件名为excel

我已经创build了一个代码给我的path和文件夹中的所有文件的名称来优秀。 但我的问题是它给我的文件夹中的所有文件的文件名。 我只想search和检索只有PDF文件的名字,以优秀。

这是我有什么:

Sub Example1() Dim objFSO As Object Dim objFolder As Object Dim objFile As Object Dim i As Integer 'Create an instance of the FileSystemObject Set objFSO = CreateObject("Scripting.FileSystemObject") 'Get the folder object Set objFolder = objFSO.GetFolder(Range("H1").Value) i = 1 'loops through each file in the directory and prints their names and path For Each objFile In objFolder.Files 'print file path Cells(i + 3, 2) = objFile.Path i = i + 1 Next objFile End Sub 

根据评论。 您需要testing最后三个字符是否为'pdf'

所以在for循环中添加if语句

 For Each objFile In objFolder.Files if right(objFile.Path,3) = "pdf" then 'print file path Cells(i + 3, 2) = objFile.Path i = i + 1 end if Next objFile 

这应该工作:

 Sub Find_PDF() Dim FileToCheck As String, FilePath As String, FileWildCard As String FilePath = "c:\YOUR FILE PATH\" FileWildCard = "*.pdf" FileToCheck = Dir(FilePath & FileWildCard) Do While FileToCheck <> "" i = i + 1 Sheets("Sheet1").Range("A" & i).Value = FileToCheck FileToCheck = Dir() Loop End Sub 

这不是一个免费的编码服务,但我会回答这个问题:

 For Each objFile In objFolder.Files if right(objFile.Path,3) = "pdf" then 'print file path Cells(i + 3, 2) = objFile.Path i = i + 1 end if msgbox ("Answer are here dont troll on someone") Next objFile