On Error Goto Statement

KUYJS

New Member
Joined
Sep 3, 2018
Messages
43
Hi,

Is it possible to use multiple On Error Goto statement in single vba code?

Actually in my code i want to use it twice. One on to to handle any error and one in between when giving command to delete all files on desktop. If any file is there on desktop it's working fine but when no file is on desktop it is considering top on on error statement that calls to end the vba instead of resuming next that i want for second on error statement (Kill path).
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
An alternative approach

- copy "dummy" file to the desktop before trying to delete all files
- guarantees there is always a file to delete
- avoid the risk of error

Here a file is copied and renamed with a timestamp
Code:
With CreateObject("Scripting.FileSystemObject")
    .CopyFile "C:\SourcePath\wbA.xlsx", "C:\DestinationPath\" & Format(Now, "YYMMDDHHMMSS") & "xlsx"
End With

(timestamp used as name to avoid any likelihood of name conflicts)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

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