Disable 'save' command in Excel 2000

S

Silena K-K

Hi

I have created a worksheet form in Excel which will be used as a template
and want to be able to disable the save command.

The idea is that the users enter their data, print out the results and then
close the form without it saving. We want the form to automatically close
without saving, not ask the user whether they want to save or not.

Is there a macro command and/or code that can do that??

Thanks and Merry Christmas. Silena
 
G

Gord Dibben

Entered into Thisworkbook module to cover user hitting the Save Icon or
File>Save.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ThisWorkbook.Saved = True
ThisWorkbook.Close
End Sub

Workbook will close with no save taking place because you have faked it out with
"I'm already saved".

You may want to also put code into the BeforeClose event.to cover them just
closing. Workbook will close with no save or alert.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Saved = True
End Sub


Gord Dibben MS Excel MVP
 
S

Silena K-K

Hi Gord

I have tried this and it doesn't seem to work - although it's highly likely
that I'm not writing it into VB correctly.

I copied the text below from "Private Sub" to "End Sub" and pasted it into
VB by selecting Tools, Macros, VB Editor and then double clicking on the
"This workbook" module and pasting the code into the blank screen.

Is that correct??

Silena
 
G

Gord Dibben

Yes, that is the proper module to have it in.

But first time you save or close, the workbook will close without saving the
code. My mistake in not explaining this.

Steps to take................

Open the workbook.

Paste the code into Thisworkbook module.

View>Immediate Window.

Type in Application.EnableEvents = False then ENTER key

File>Save the workbook. You will be asked if you want to save changes.

Yes, you do.

Back to the Immediate Window and Application.EnableEvents = True.

Your code when closing or saving the workbook should now work properly.


Gord
 
S

Silena K-K

Hi Gord

Still doesn't work.

At the step "File>Save the workbook" I don't get ask if I want to save
changes and the "Application.EnableEvents" does not change from False to True.

Silena
 
G

Gord Dibben

You have to manually change Application.EnableEvents to True

I'm off now for horses hooves and libations so won't get back untill tomorrow.


Gord
 
S

Silena K-K

Hi Gord

I followed your steps and have the following code in VB but now when I use
"ctrl s" or F12 to test that the save doesn't work it crashes Excel. Any
ideas why? Silena

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ThisWorkbook.Saved = True
ThisWorkbook.Close

End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Saved = True

End Sub
 
G

Gord Dibben

I cannot replicate your crashing problem with CTRL + s and F12

Did you reenable events after saving the workbook with the code?

I would presume so.

What happens with File>Save?

What happens when you click on the "Save" Icon on Toolbar?

What happens when you just Close the workbook?

If you want to send me the workbook to me via email I can have a look.

Change the AT and DOT to appropriate punctuation in my posting address.


Gord
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top