Solved

MESSAGE WHEN CLIKING IN NO SAVE AT EXIT

Posted on 2011-02-26
7
326 Views
Last Modified: 2012-05-11
Hi,

I need to prompt a message (yes/no) when the user close the workbook and select NO when is asked to save the changes.
If the user selects No then the message should prompt asking again if you are sure....

I need to add this feature in order to avoid a problem is happening due to similarity in two different files...

Thank you for your time,
Roberto.
0
Comment
Question by:Pabilio
  • 4
  • 2
7 Comments
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34990213
Roberto: What is the user first saves and then clicks on the Close button?

Sid
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34990219
I think this is what you want?

Sample File attached.

Sid

Code Used

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    If SaveAsUI <> True Then
        Dim Ret
        Ret = MsgBox("Are you sure you want to save", vbYesNo)
        If Ret = vbYes Then
            Ret = MsgBox("Are you doubly sure you want to save", vbYesNo)
            If Ret <> vbYes Then
                Cancel = True
            End If
        End If
    End If
End Sub

Open in new window


Save-Example.xls
0
 
LVL 5

Author Comment

by:Pabilio
ID: 34990274
Hi Sid,

Congratulations on your Genius rank !!...

What I need is to prompt the user that he is closing the workbook without saving it first.

If the user do some changes in the file, when closing it the "do you want to save changes window" will be displayed... right ?...
If the user click NO in this window, then I need (if is possible) to prompt the message saying the "Are you sure you want to exit without saving?"...

I know it sound a bit crazy, but I need it this way in order to avoid an error that sometimes is happening due that We have another similar file that does not allows changes and the users are used to exit it without saving changes... (they automatically click NO when are prompted to save changes).

Thank you for your help.
Roberto.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34990282
Pabilio: Thanks :)

>> If the user click NO in this window, then I need (if is possible) to prompt the message saying the "Are you sure you want to exit without saving?"...

I am not sure if you can do that...

Sid
0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 34990299
You might want to use the BeforeClose event and check on the Saved state of the workbook...

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    If Not Me.Saved Then
        Select Case MsgBox("Would you like to save the changes made to this workbook?", vbYesNoCancel)
            Case vbYes
                Me.Save
            Case vbNo
                If MsgBox("Are you sure you want to exit without saving?", vbYesNo) = vbYes Then
                    Me.Saved = True
                Else
                    Me.Save
                End If
            Case vbCancel
                Cancel = True
        End Select
    End If
End Sub

Open in new window


This will display the "Are You sure..." message box if they click no. It will then ignore any changes when they click "Yes", or will save when they click "No".

Wayne
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34990303
webtubbs: nice one :)

I never thought of that angle. I was thinking more into hooking into that message box ;)

Sometimes you simply miss the obvious.

Sid
0
 
LVL 5

Author Closing Comment

by:Pabilio
ID: 34990346
Excellent Wayne...
Thank you.
Roberto.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question