4

I have this Error Message, i'm completely lost...

I think I checked everything that could be wrong, maybe one of you guys can see a mistake or something. My brain is now completely blocked.

Thanks in advance

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
Chris
  • 53
  • 1
  • 1
  • 6
  • which line gives you that error –  Oct 22 '13 at 07:30
  • `For Each objFile In objFolder.SubFolders` – Chris Oct 22 '13 at 08:01
  • do a `Debug.print folderPath` just before you call the `getNewestFile` and make sure the path is correct. –  Oct 22 '13 at 08:12
  • the path is actually correct, but the path is 251char long, if that could be a problem, i don't think but...yeah – Chris Oct 22 '13 at 09:04
  • no, the path can be longer than 251 characters. But if the path is not found that 99.9% of the time mean it's not a valid path :P –  Oct 22 '13 at 09:19
  • yeah i know that, but i checked it manually and the path was correct.. – Chris Oct 22 '13 at 11:08

4 Answers4

1

Allright I found an answer! Windows can only handle paths under 255 characters.

So all you have to do is add \\?\ before a path, for example \\?\c:\users on server adressen you have to add \\?\unc --> \\?\unc\servername\path

Hope that helps you out!

Dominique
  • 16,450
  • 15
  • 56
  • 112
Chris
  • 53
  • 1
  • 1
  • 6
1

I get this error when the file I am trying to reach is in SharePoint. As a workaround what I do is I will open that link in Explorer view (SharePoint link - Library - Connect & Export - Open with Explorer). Once I have the SP in explorer view it functions smoothly. To resolve this we have to map that SP link into a drive and call the drive address instead of SP link. Link for that - Get the content of a sharepoint folder with Excel VBA

0

It could be caused by the long file name due to extensive folder & subfolder of a file to be copied.

Try reduce the length of the name of all the folders / subfolders before you copy.

It solve my problem, hope solving yours too.

Regards,

0

I had exactly the same symptom, but un-understandibly, I could make the symptom go away by unchecking "Run as administrator" for the shortcut that starts the app :\

Maybe this is helpful for people experiencing the same symptom, and nothing else helped.

TheBlastOne
  • 4,291
  • 3
  • 38
  • 72