Consulting

Results 1 to 3 of 3

Thread: Run-time error 53 when moving files

  1. #1

    Run-time error 53 when moving files

    Hello All, i am trying to move newly created files (invoice files) into also newly created folder for each.
    I am creating a .xlsx file and .pdf file, and want to move them both in the new folder.
    But i get run-time error 53 when doing so, if i get rid of the xlsx file, moves the pdf file with no problem, once i tell it to move the xlsx file, it gives me the error, but the file is present.
    How can i fix that, here is my code:

    Sub SaveAsPDF()
    'SaveAsPDF-Inv Macro
    ' Save a pdf of file and name it
    If Len(Dir("C:\Users\mtodorovski\Dropbox\INVOICES\INVOICE#00" & Range("F5").Value & Property, vbDirectory)) = 0 Then
        MkDir "C:\Users\mtodorovski\Dropbox\INVOICES\INVOICE#00" & Range("F5").Value & Property
    End If
    ChDir "C:\Users\mtodorovski\Dropbox\INVOICES"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:="C:\Users\mtodorovski\Dropbox\INVOICES\" & "00" & Range("F5").Value
    Dim NewFN As Variant
    ActiveSheet.Copy
    NewFN = "C:\Users\mtodorovski\Dropbox\INVOICES\INVOICE#00" & Range("F5").Value
    ActiveWorkbook.SaveAs NewFN, FileFormat:=xlOpenXMLWorkbook
    ActiveWorkbook.Close
    Application.Wait (Now + TimeValue("0:00:01"))
    Dim FSO As Object
        Dim FromPath As String
        Dim ToPath As String
        Dim FileExt As String
        Dim FileName As String
    FromPath = "C:\Users\mtodorovski\Dropbox\INVOICES"  '<< Change
        ToPath = "C:\Users\mtodorovski\Dropbox\INVOICES\INVOICE#00" & Range("F5").Value    '<< Change
    FileExt = "*.pdf"
        FileName = "INVOICE#00" & Range("F5").Value '<< Change
        'You can use *.* for all files or *.doc for Word files
    If Right(FromPath, 1) <> "\" Then
            FromPath = FromPath & "\"
        End If
    Set FSO = CreateObject("scripting.filesystemobject")
    If FSO.FolderExists(FromPath) = False Then
            MsgBox FromPath & " doesn't exist"
            Exit Sub
        End If
    If FSO.FolderExists(ToPath) = False Then
            MsgBox ToPath & " doesn't exist"
            Exit Sub
        End If
    Application.Wait (Now + TimeValue("0:00:04"))
    FSO.MoveFile Source:=FromPath & FileExt & FileName, Destination:=ToPath
    End Sub

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Welcome to the forum!

    Check your order and missing backslash character. Press Ctrl+G after a run to view the result below.
      Debug.Print FromPath & FileExt & Filename
     'FSO.MoveFile Source:=FromPath & FileExt & FileName, Destination:=ToPath

  3. #3
    Quote Originally Posted by Kenneth Hobs View Post
    Welcome to the forum!

    Check your order and missing backslash character. Press Ctrl+G after a run to view the result below.
      Debug.Print FromPath & FileExt & Filename
     'FSO.MoveFile Source:=FromPath & FileExt & FileName, Destination:=ToPath
    THANKS KEN, I JUST DOUBLED THE FILE EXT AND TO PATH BELOW EVERYTHING AND IT WORKED, MACRO DOES WHAT I EXPECT IT SO I LEFT IT ALONE HAHA.

    THANKS FOR YOUR KIND REPLY

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •