4

私はこのエラーメッセージを持っています、私は完全に迷っています...

間違っている可能性のあるものはすべてチェックしたと思います。おそらく、誰かが間違いか何かを見ることができます。私の脳は完全にブロックされています。

前もって感謝します

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
4

4 に答える 4

1

よし、答えを見つけた!Windows は 255 文字未満のパスのみを処理できます。

したがって\\?\、パスの前に追加するだけです。たとえば\\?\c:\users、サーバーアドレスに追加する必要があります\\?\unc-->\\?\unc\servername\path

それがあなたを助けることを願っています!

于 2013-10-25T08:54:29.887 に答える
0

コピーするファイルのフォルダーとサブフォルダーが大きいため、ファイル名が長いことが原因である可能性があります。

コピーする前に、すべてのフォルダー/サブフォルダーの名前の長さを短くしてみてください。

それは私の問題を解決します。あなたの問題も解決することを願っています。

よろしく、

于 2015-06-02T06:55:38.967 に答える