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).
 

Some videos you may like

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
5,274
Office Version
365
Platform
Windows
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:

Watch MrExcel Video

Forum statistics

Threads
1,089,739
Messages
5,410,146
Members
403,298
Latest member
The Noob

This Week's Hot Topics

Top