Error Trapping Question
Hi there Barb,
With something as simple as deleting a sheet, you can probably get away with
an 'On error resume next' statement. Example:
Sub DeleteSheet2()
On error resume next
Sheets("Sheet1").delete
End sub
This may not be very well structured for anything larger and it certainly
doesn't really give you much to work with. If doing this more than one time
(deleting sheets) I recommend you test for it, which I generally do with
another routine. Example:
Sub DeleteSheet3()
if WsExists("Sheet1", "Book1.xls") then
workbooks("Book1.xls").Sheets("Sheet1").Delete
End sub
Function WsExists(wsName as string, Optional wbName as string) as boolean
On error resume next
if wbName = "" then wbName = Activeworkbook.name
WsExists = Len(Workbooks(wbname).Sheets(wsname).name)
End function
Is this what you were looking for?
HTH
--
Regards,
Zack Barresse, aka firefytr, (GT = TFS FF Zack)
To email, remove the NO SPAM. Please keep correspondence to the board, as
to benefit others.
"Barb Reinhardt" wrote in message
...
I have this simple macro
Sub DeleteSheet()
Sheets("Sheet1").Select
ActiveWindow.SelectedSheets.Delete
End Sub
How should I modify it so that if Sheet1 isn't present, it'll just move
on.
I'll want to add more to this at a later time, so Exit Sub may not
necessarily be an option.
|