Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Cancel "Do you want to save" message


Reply
 
Thread Tools Display Modes
  #1  
Old 09-28-2005, 08:29 AM
King5555 King5555 is offline
Junior Contributor
 
Join Date: Jul 2003
Posts: 336
Default Cancel "Do you want to save" message


I want to only allow people to save over this document if they hit a button on the worksheet. I did this with the beforesave event and had no problem. The only issue is if they make changes and then just go and close the document. It will ask if they want to save the changes. I tried setting the displayalerts to false but that doesn't seem to work. I also don't want the file to be read only because I want them to be able to save the new values in the document by clicking the button. How can I have it close without asking for a save?

Thanks!
Reply With Quote
  #2  
Old 09-28-2005, 08:49 AM
George7a's Avatar
George7a George7a is offline
Saved by Grace
 
Join Date: Mar 2005
Location: Nazareth
Posts: 1,697
Default

type in the code filed of the workbook following
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean) If Me.Saved = False Then Me.Saved = True End Sub

Now you won't be prompted each time you close the workbook.
Do not forget to save this change

- George
Reply With Quote
  #3  
Old 09-28-2005, 09:35 AM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Hey King,

If you acheive what you want, they could make a lot of changes and forget to hit your save button... Then exit and loose all their changes w/o any warnings at all.

Are you sure that you want this? Would they??

If you really don't like the default message, then I would at least give them a chance to save by calling your own "Do you want to save changes?" message followed by your own version of Save (whatever you might be doing differently). I really would give them a chance to not lose all their work...
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
  #4  
Old 09-28-2005, 09:52 AM
King5555 King5555 is offline
Junior Contributor
 
Join Date: Jul 2003
Posts: 336
Default

I'm definitely putting in my own message, I just wanted to avoid the default. Thanks for the help George; it works great. I'm not sure I quite understand what it's doing though. Is it fooling the document into thinking it was already saved?
Reply With Quote
  #5  
Old 09-28-2005, 09:55 AM
italkid's Avatar
italkid italkid is offline
Down...

Retired Moderator
* Expert *
 
Join Date: Dec 2002
Location: Belgium.
Posts: 6,731
Default

And what in case a user don't want the changes he/she made, for instance because of possible mistakes. In that case people tend to close the file without saving changes and reopen it...

Last edited by italkid; 09-28-2005 at 10:34 AM.
Reply With Quote
  #6  
Old 09-28-2005, 09:57 AM
King5555 King5555 is offline
Junior Contributor
 
Join Date: Jul 2003
Posts: 336
Default

So this code is automatically saving any changes? I definitely don't want the changes saved or the prompt to appear...
Reply With Quote
  #7  
Old 09-28-2005, 10:03 AM
italkid's Avatar
italkid italkid is offline
Down...

Retired Moderator
* Expert *
 
Join Date: Dec 2002
Location: Belgium.
Posts: 6,731
Default

No, no, it makes Excel think the file is saved already, I did misread George's code...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->