Solved

MESSAGE WHEN CLIKING IN NO SAVE AT EXIT

Posted on 2011-02-26
7
324 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tags from access to excel 3 28
FormulaArray VBA Issue 6 17
Excel Copy Macro down foe each row 4 18
Check folder every for files and print them 5 21
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,…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

912 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now