PDA

View Full Version : Close out without saving



talytech
05-28-2008, 09:11 AM
I have a workbook that displays a form from a button (Riskform.Show). On that form is an approve button. When the user clicks that button I want an email sent and the workbook closed without it asking you to save. I thought my code was ok but it promts me to save. Can someone please assist me with this problem? Here is my code behind the Approve button on the userform. The userform is called "RiskForm"


Dim theName, theSub, theRecipient As String


If Worksheets("sheet1").CheckBox1.Value = True And Worksheets("sheet1").CheckBox2.Value = False Then
RiskForm.Hide
theName = "FTE - " & Worksheets("sheet1").Range("c21") & " " & Worksheets("sheet1").Range("f21") & " " & Worksheets("sheet1").Range("h21")
theSub = "SUBMITTAL: EXCEPTION REQUEST FORM FOR (" & theName & ")"

theRecipient = "corporate_security@fanniemae.com"
ActiveWorkbook.SendMail theRecipient, theSub

ActiveWorkbook.Close SaveChanges:=False
Application.Quit
ElseIf Worksheets("sheet1").CheckBox1.Value = False And Worksheets("sheet1").CheckBox2.Value = True Then
RiskForm.Hide
theName = "Contractor - " & Worksheets("sheet1").Range("c25") & " " & Worksheets("sheet1").Range("f25") & " " & Worksheets("sheet1").Range("h25")
'send the email
theSub = "SUBMITTAL: EXCEPTION REQUEST FORM FOR (" & theName & ")"
theRecipient = "corporate_security@talytech.com"
ActiveWorkbook.SendMail theRecipient, theSub

ActiveWorkbook.Close SaveChanges:=False
Application.Quit
End If

Simon Lloyd
05-28-2008, 10:19 AM
You just need the line:

Thisworkbook.Saved = True
it tells excel that the save has been performed even though it hasn't!

talytech
06-03-2008, 07:25 AM
thank you. Do I put that line after
ActiveWorkbook.Close SaveChanges:=False
Application.Quit or do I just replace the activeworkbook.close savechanges:= false with Thisworkbook.Saved = True?

mdmackillop
06-03-2008, 07:30 AM
Please use linebreaks where long lines of code require scrolling.

Simon Lloyd
06-03-2008, 08:37 AM
thank you. Do I put that line after
ActiveWorkbook.Close SaveChanges:=False
Application.Quit or do I just replace the activeworkbook.close savechanges:= false with Thisworkbook.Saved = True?You use it like this Thisworkbook.Saved = True
Thisworkbook.closebefore

mdmackillop
06-04-2008, 12:04 AM
You may also want to use

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True
End Sub


in case they try to save in some other way.

Bob Phillips
06-04-2008, 01:42 AM
Please use linebreaks where long lines of code require scrolling.


... and/or use With ... End With