Solved

MESSAGE WHEN CLIKING IN NO SAVE AT EXIT

Posted on 2011-02-26
7
329 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

717 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