FileCopy where destination does not exist

cfoye130

Board Regular
Joined
Aug 12, 2008
Messages
84
I am trying to use vba to archive a file, however the name of the file is new each day, In-flight_40609.pdf.

The problem is that using "FileCopy source, dest" errors since the destination does not exist before I try to copy it. How can I get around this?

Thanks!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I just want to get my file copied to the destination.....

Every day I have a file called In-Flight.pdf that is re-created and stored in a directory. I am trying to get that file, copied to a new destination, named In-Flight with a datestamp.pdf, e.g. In-Flight_040609.pdf. An archive of sorts. This happens before the In-flight.pdf gets overwriten with the new days file.
 
Upvote 0
Does this work?

Code:
    Const sSrcPath  As String = "C:\source path\"
    Const sDstPath  As String = "C:\destination path\"
    Const sFile     As String = "In-Flight"
    Const sExt      As String = ".pdf"
 
    If Len(Dir(sSrcPath & sFile & sExt)) = 0 Then
        MsgBox "Source path or file doesn't exist"
    ElseIf Len(Dir(sDstPath, vbDirectory)) = 0 Then
        MsgBox "Destination path doesn't exist"
    Else
        FileCopy sSrcPath & sFile & sExt, _
                 sDstPath & sFile & Format(Date, "yymmdd") & sExt
    End If
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,626
Members
452,933
Latest member
patv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top