Error 52 "Bad file name or number"

  • I have following macros:


    after ~500 files it returns error 52 "Bad file name or number"


    May somebody to help to solve the problem.
    Thanks

  • Re: Error 52 "Bad file name or number"


    Try the following modification to find the problem filename.
    [vba]Dim SourceFile, DestinationFile, SourceFileExt
    SourceFile = Application.GetOpenFilename("Acrobat Files (*.pdf),*.pdf,Excel Files (*.xls),*.xls,Word Files (*.doc), *.doc")
    SourceFileExtension = Right(SourceFile, 3)
    DestinationPath = GetFolderPath
    i = 2
    On Error GoTo BadFile
    Do Until Cells(i, 1) = ""
    DestinationFile = DestinationPath & "\" & Cells(i, 1) & "." & SourceFileExtension
    FileCopy SourceFile, DestinationFile
    i = i + 1
    Loop
    MsgBox "All done with no errors.", vbOKOnly + vbInformation, "Success!"
    Exit Sub
    BadFile:
    MsgBox "Problem on line " & i & ". The bad filenames was " & Cells(i, 1), vbOKOnly + vbCritical, "Bad Filename"
    End Sub[/vba]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!