Consulting

Results 1 to 7 of 7

Thread: Close out without saving

  1. #1

    Close out without saving

    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

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    You just need the line:
    [VBA]
    Thisworkbook.Saved = True
    [/VBA]it tells excel that the save has been performed even though it hasn't!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    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?

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Please use linebreaks where long lines of code require scrolling.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Quote Originally Posted by talytech
    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 [VBA]Thisworkbook.Saved = True
    Thisworkbook.close[/VBA]before
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You may also want to use
    [VBA]
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Cancel = True
    End Sub

    [/VBA]
    in case they try to save in some other way.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by mdmackillop
    Please use linebreaks where long lines of code require scrolling.

    ... and/or use With ... End With
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •