2013-10-22 335 views
1

我有这样的错误消息,我完全失去了...运行时错误76找不到路径

我想我检查一切,这可能是错误的,你们可以看到一个错误或东西也许有。我的大脑现在完全被阻塞了。

在此先感谢

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 
+0

这行给出了这样的错误 – 2013-10-22 07:30:24

+0

'对于每个OBJFILE在objFolder.SubFolders' – Chris

+0

做了'Debug.print folderPath'调用'getNewestFile'并确保路径是正确的之前。 – 2013-10-22 08:12:23

回答

0

奥莱特我找到答案!窗户只能处理路径下255characters ...

因此,所有你需要做的就是添加\ \路径之前,例如\\?\c:\users在服务器adressen你必须添加\ \ UNC? - >\\?\unc\servername\path

希望能帮到你!

0

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

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

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

问候,