PDA

View Full Version : Solved: Sheets.Delete



Nader
02-22-2008, 02:30 AM
I used this code to delete a sheet
Sheets(2).Delete


And window show a message to delete or cancel as it show in the pic below
I want if I chose delete or cancel . It will release a code


Example : if I press delete choice. It will shows
MsgBox "The sheet has deleted"


And thank you for help

Bob Phillips
02-22-2008, 03:11 AM
You would need to throw upo your own message boxes, then use DisplayAlerets to suppress the system message.

Nader
02-22-2008, 04:16 AM
How?

Bob Phillips
02-22-2008, 04:37 AM
Msgbox

If Msgbox(msg) = vbYes Then

Application.DisplayAlerts = False
Worksheets(the_ws_in_question).Delete
Application.DisplayAlerts = True
End If

Nader
02-22-2008, 06:21 AM
Why did'n't do the process TextBox1.Text = 5 after choce delet choice

Private Sub CommandButton1_Click()
Sheets(2).Delete ' after do this process it will do this code
If MsgBox(msg) = vbYes Then
Application.DisplayAlerts = False
Worksheets(the_ws_in_question).Delete
Application.DisplayAlerts = True
TextBox1.Text = 5 ' it didn't do this process
End If
End Sub

Bob Phillips
02-22-2008, 07:23 AM
That is not the order in which I suggested it. as I said ...

You would need to throw up your own message boxes, then use DisplayAlerets to suppress the system message

SO you give a Msgbox saying the data can be lost, then a Yes/No Msgbox asking if ok, then if they say yes, then you delete it with messages suppressed.

Nader
02-22-2008, 09:00 AM
Here is the code What do you think about it is it possible

a = MsgBox("Do you want to delete A worksheet ?!", vbYesNo, "Delete Worksheet")

If a = vbYes Then
Application.DisplayAlerts = False
Sheets(2).Delete
Application.DisplayAlerts = True
TextBox1.Text = 5 ' it didn't do this process
End If

Bob Phillips
02-22-2008, 09:05 AM
That looks about rigt. Have you tried it?

Nader
02-22-2008, 09:35 AM
Yes, I tried .
Thank you for help.