【问题标题】:Runtime Error 76 Path not found运行时错误 76 找不到路径
【发布时间】:2013-10-22 07:27:22
【问题描述】:

我收到此错误消息,我完全迷路了......

我想我检查了所有可能出错的地方,也许你们中的一个人可以看出错误或其他什么。我的大脑现在完全被阻塞了。

提前致谢

Option Explicit

Public newestFile As Object

Sub Scan_Click()
    Dim path As String
    Dim row As Integer: row = 2
    Dim ws As Worksheet

    Set ws = ThisWorkbook.Sheets("ETA File Server")

    With ws
        Do
            If .Cells(row, 1).Value = "" Then Exit Do

            path = .Cells(row, 1).Value

            Application.StatusBar = "Processing folder " & path
            DoEvents

            If .Cells(row, 1).Value <> "Root" Then
                Call getNewestFile(path)

                .Cells(row, 9).Value = newestFile.DateLastModified
                .Cells(row, 10).Value = newestFile.Name

                Set newestFile = Nothing
                row = row + 1
            Else
                row = row + 1
            End If
        Loop
    End With

    Application.StatusBar = "Done"
End Sub

Private Sub getNewestFile(folderpath As String)
    Dim objFSO As Object, objFolder As Object, objFile As Object

    'get the filesystem object from the system
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(folderpath)

    'go through the subfolder and call itself
    For Each objFile In objFolder.SubFolders
        Call getNewestFile(objFile.path)
        DoEvents
    Next


    For Each objFile In objFolder.Files
        If newestFile Is Nothing Then
            Set newestFile = objFile
        ElseIf objFile.DateLastModified > newestFile.DateLastModified Then
            Set newestFile = objFile
        End If
    Next
End Sub

【问题讨论】:

  • 哪一行给你那个错误
  • For Each objFile In objFolder.SubFolders
  • 在调用getNewestFile 之前执行Debug.print folderPath 并确保路径正确。
  • 路径实际上是正确的,但路径是 251char 长,如果这可能是一个问题,我不认为但是......是的
  • 不,路径可以超过 251 个字符。但是如果没有找到路径,那 99.9% 的时间意味着它不是一个有效的路径:P

标签: excel vba runtime-error


【解决方案1】:

当我尝试访问的文件位于 SharePoint 中时,我收到此错误。 作为一种解决方法,我将在资源管理器视图中打开该链接(SharePoint 链接 - 库 - 连接和导出 - 使用资源管理器打开)。一旦我在资源管理器视图中拥有 SP,它就会顺利运行。 为了解决这个问题,我们必须将该 SP 链接映射到驱动器并调用驱动器地址而不是 SP 链接。 链接 - Get the content of a sharepoint folder with Excel VBA

【讨论】:

    【解决方案2】:

    好的,我找到了答案! Windows 只能处理 255 个字符以下的路径。

    所以你所要做的就是在路径前添加\\?\,例如\\?\c:\users在服务器地址上你必须添加\\?\unc --> \\?\unc\servername\path

    希望能帮到你!

    【讨论】:

      【解决方案3】:

      这可能是由于要复制的文件的文件夹和子文件夹过长,导致文件名过长。

      复制前尽量缩短所有文件夹/子文件夹的名称长度。

      它解决了我的问题,希望也能解决你的问题。

      问候,

      【讨论】:

        【解决方案4】:

        我有完全相同的症状,但令人难以理解的是,我可以通过取消选中启动应用程序的快捷方式的“以管理员身份运行”来消除症状:\

        也许这对遇到相同症状的人有帮助,但没有其他帮助。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-07-03
          • 2018-08-26
          • 1970-01-01
          • 2020-05-26
          • 2018-12-03
          • 2012-12-01
          • 1970-01-01
          相关资源
          最近更新 更多