运行时错误76找不到path

我有这个错误消息,我完全失去了…

我想我查了一切可能是错误的,也许你们中的一个人可以看到一个错误或什么的。 我的大脑现在完全被阻塞了。

提前致谢

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 

好吧,我find了答案! Windows只能处理255个字符以下的path…

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

希望能帮助你!

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

在复制之前,请尝试缩小所有文件夹/子文件夹的名称长度。

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

问候,