VBA - If error carry on

p4nny

Board Regular
Joined
Jan 13, 2015
Messages
246
Hi,

I have the following code which moves files from one location to another.. If a file doesn't exist, I would the code to carry on to the next file rather give an error message "File does not exist"

appreciate any guidance you can give.
Code:
Sub everythingexcCRO()


Kill "\\retail\dfsroot$\Group Change\Database use only\02-01 Logistics.xlsm"




FileCopy Source:="\\retail\dfsroot$\Group Change\02-01 Logistics\02-01 Logistics.xlsm", Destination:="\\retail\dfsroot$\Group Change\02-01 Logistics.xlsm"


'logistics




Kill "\\retail\dfsroot$\Group Change\Database use only\03-01 Fulfilment.xlsm"


FileCopy Source:="\\retail\dfsroot$\Group Change\03-01 Fulfilment.xlsm", Destination:="\\retail\dfsroot$\Group Change\Database use only\03-01 Fulfilment.xlsm"


'fulfillment
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
You can use Dir to verify the file exists:

Code:
sFileTo = "\\retail\dfsroot$\Group Change\Database use only\02-01 Logistics.xlsm"
sFileFrom = Replace(sFileTo, "Database use only\", "")
If Dir(sFileTo) <> "" then Kill sFile
   If Dir(sFileFrom) <> "" Then FileCopy Source:=sFileFrom, Destination:=sFileTo

Since it looks like you repeat this more than once, it may be worth putting into a separate routine and passing the "Database use only" path as an argument to it.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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