Solved

MESSAGE WHEN CLIKING IN NO SAVE AT EXIT

Posted on 2011-02-26
7
322 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
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…

706 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

19 Experts available now in Live!

Get 1:1 Help Now