【问题标题】:Excel-VBA Find a pdf file given a pathExcel-VBA 查找给定路径的pdf文件
【发布时间】:2011-05-18 11:04:39
【问题描述】:

问题:
我需要知道在一系列文件夹中放置了哪些文件。我想对每个文件夹中有哪些文件进行编目,并且可以随时检查,而无需手动进入每个文件夹。一种将不同目录中的多个文件“同步”到集中目录的方式,这样如果我从文件夹中删除文件,目录就会反映更改。

我希望 Excel 可以帮助解决这个问题。简而言之,我希望能够做到这一点:

Filename     FilePath                     Exists

abc_4.23.11  C:\4-23-11\abc_4.23.11.pdf   *True/False*

细节/假设:

主目录不会因文件而改变。因此文件“abc.pdf”将始终位于同一文件夹中。

假设文件夹 1 具有以下约定:

文件夹名称:mm-dd-yy (i.e 4-30-11)

文件夹 1 的内容:一系列其他子文件夹,我们将使用字母来称呼它们,因此文件夹 A、文件夹 B、文件夹 C...文件夹 Z。

在每个子文件夹中都有一个 pdf 文件,我需要确认它在那里。

如果有任何问题,请告诉我。

谢谢一百万!

【问题讨论】:

  • 查看this thread 了解一些想法。
  • 不幸的是,我认为 Excel 不会对您有太大帮助。

标签: excel vba


【解决方案1】:

这可能有助于开始:

Sub ListAllFiles() 
Dim fs As FileSearch, ws As Worksheet, i As Long 
Set fs = Application.FileSearch 
With fs 
    .SearchSubFolders = False ' if you want to search the sub folders also, set to true
    .FileType = msoFileTypeAllFiles 'change this depending on the types of files you would like to filter
    .LookIn = "C:\"  'this will be the search location
    If .Execute > 0 Then 
        Set ws = Worksheets.Add 
        For i = 1 To .FoundFiles.Count 
            ws.Cells(i, 1) = .FoundFiles(i) 
        Next 
    Else 
        MsgBox "No files found" 
    End If 
End With 
End Sub

您需要做的是创建检查文件是否仍然存在的位。希望这会有所帮助

【讨论】:

    猜你喜欢
    • 2017-04-29
    • 2018-03-20
    • 1970-01-01
    • 2014-03-13
    • 2011-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多