2013-10-22 361 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

可能是由於要複製的文件的廣泛文件夾&子文件夾導致長文件名。

嘗試在複製之前縮短所有文件夾/子文件夾的名稱長度。

它解決了我的問題,希望解決你的問題。

問候,