运行时错误 76 未找到路径

Chr*_*ris 5 excel vba runtime-error

我有这个错误消息,我完全迷失了......

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

提前致谢

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
Run Code Online (Sandbox Code Playgroud)

Chr*_*ris 1

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

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

希望对您有所帮助!