Solved

MESSAGE WHEN CLIKING IN NO SAVE AT EXIT

Posted on 2011-02-26
7
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

733 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