Try using "Application.DisplayAlerts = False
way ahead of you. doesn't work thanks though
Assuming your code looks something like this it should work:
Dim Msg As String, Ans As String
If Not Me.Saved Then
Msg = "Do yo want to save the changes made to"
Msg = Msg & Me.Name & "?"
Ans = MsgBox(Msg, vbQuestion + vbYesNoCancel)
Select Case Ans
Case vbYes
M.Save
Case vbNo
Me.Saved = True
Case vbCancel
Cancel = True
Exit Sub
End Select
End If
End Sub
my code is very simple.
I have made a form called UserForm1
in ThisWorkBook
Public Sub Workbook_BeforeClose(Cancel As Boolean)
UserForm1.Show
End Sub
in the form I have
Private Sub CommandButton1_Click()
bClose = True
ActiveWorkbook.Save
Unload UserForm1
Application.Quit
End Sub
Private Sub CommandButton2_Click()
Unload UserForm1
End Sub
Private Sub CommandButton3_Click()
Call Sheet1.NewWork
Unload UserForm1
End Sub
Try this........
Private Sub CommandButton1_Click()
bClose = True
ActiveWorkbook.Save
Unload UserForm1
Application.Quit
End Sub
Private Sub CommandButton2_Click()
Unload UserForm1
ShouldWe 0, False
End Sub
Private Sub CommandButton3_Click()
Call Sheet1.NewWork
Unload UserForm1
ShouldWe 0, False
End Sub
Then in a Module add this Function
Static Function ShouldWe(From, Optional CloseIt As Boolean) As Boolean
'From = any number > 0 means it is called from another routine
' otherwise it was called from the userform
If From > 0 Then
If CloseIt = False Then
ShouldWe = False
Else
ShouldWe = True
End If
End If
End Function
Your Thisworkbook code should then be;
Private Sub Workbook_BeforeClose(Cancel As Boolean)
UserForm1.Show
If Not ShouldWe(1) Then Cancel = True
End Sub
Ivan
Missed one small piece of code
should add
Application.enableevents=false
IN HERE >>>> Try this........ Private Sub CommandButton1_Click()
>>>>>