LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Delete Sheet executing macro

I have a sheet that has a command button. One of the tasks I want the macro
do to is delete the sheet that the command button is on. What is the proper
way to do that?

What do you think of this:

On Sheet3 code:

Private Sub cmdMigrateWB_Click()
MigrateWorkbook
end sub

In Module1:

Sub MigrateWorkbook()

On Error GoTo ErrThisSub

' Do a bunch of stuff

prevValue = Application.DisplayAlerts
Application.DisplayAlerts = False
On Error Resume Next

'delete the sheet the cmd button was on
Sheets(3).Delete
On Error GoTo ErrThisSub
Application.DisplayAlerts = prevValue

' do some more stuff

Exit Sub

ErrThisSub:
MsgBox "Error in routine."

End Sub

It seems to work, but it seems wrong to delete the code that the Module1
macro is trying to return to. The main effect I've seen is that I can't enter
debug after the delete has occured.

Suggestions?

Thanks,
John
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use macro to delete worksheet without specific name Eg:Sheet 1 Delight Excel Programming 5 November 19th 08 01:01 AM
need to modify a macro to prevent it from executing if in wrong area of the sheet Tonso Excel Discussion (Misc queries) 3 February 11th 07 08:00 PM
Macro for sheet delete, very easy comotoman Excel Discussion (Misc queries) 1 October 11th 05 11:19 PM
recording macro to delete sheet Marcia[_2_] Excel Programming 5 May 12th 04 10:13 PM
macro to delete a sheet MoiraGunn Excel Programming 2 September 3rd 03 06:11 AM


All times are GMT +1. The time now is 06:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"