ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Preventing Users From Saving An Excel Workbook (https://www.excelbanter.com/excel-programming/330888-preventing-users-saving-excel-workbook.html)

LocVez

Preventing Users From Saving An Excel Workbook
 

Hi All,

I`m looking for code to prevent a user from saving an excel workbook, i
barely remember playing with code at the beginning of this year in class
that displayed a message saying "Sorry, this workbook cannot be saved"
if the user attempted to save the file.

I`m working on a college project and have a very simple piece of code
that handles "registration". So if a user presses the button named
"register" they are taken to a form to insert the registration code. I
managed to get the code to enable and disable the Register button if
the code entered is correct, store it in a sheet and check it on close
and startup of the workbook.

Now the fun part, if the registration number aint been entered, or is
invalid, then the user isn't allowed to save anything they enter,
muhahahaha.

If i rememebr correctly, it's very simple to do, something to do with
the message boxes that displays information, OK/CANCEL, etc. but i
can't for the life of me rememebr the code.

I`m gonna dig out my old notes anyway. I`d be gratefull for any
assistance :)


~LocVez


--
LocVez
------------------------------------------------------------------------
LocVez's Profile: http://www.excelforum.com/member.php...o&userid=24021
View this thread: http://www.excelforum.com/showthread...hreadid=376379


LocVez[_2_]

Preventing Users From Saving An Excel Workbook
 

yay, found my notes and managed to get it, i had to go to the "workbook
section in "Microsoft excel objects" in teh VBA editor and added th
following


Code
-------------------
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
MsgBox "Sorry, You Must Register To Save This Project"
Cancel=True

-------------------



It has a IF statement to determine if the registration code has bee
inserted that i have not typed in above, so if the code is correct, th
user can save. if not, it doesnt let them.

Now, question: Would it be a good idea to terminate the program afte
the user finds out they cannot save (as it presently does)
OR
Should the user get a chance to return to the main program menu wher
they can use it more or chose to exit again? (this is what i would lik
to do)

Does anyone know how to make the program re-run instead of exiting i
this situation?

Thank's again

~LocVe

--
LocVe
-----------------------------------------------------------------------
LocVez's Profile: http://www.excelforum.com/member.php...fo&userid=2402
View this thread: http://www.excelforum.com/showthread.php?threadid=37637


Nigel

Preventing Users From Saving An Excel Workbook
 
If you cancel the save action then the progamme is terminated and control
returns to the user to enter their registration.

You could use the Workbook_BeforeClose event and test if the registration is
completed. If it is, then ask user to save the sheet, if not ask for
registration before closing. Maybe?

--
Cheers
Nigel



"LocVez" wrote in
message ...

yay, found my notes and managed to get it, i had to go to the "workbook"
section in "Microsoft excel objects" in teh VBA editor and added the
following


Code:
--------------------
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As

Boolean)
MsgBox "Sorry, You Must Register To Save This Project"
Cancel=True

--------------------



It has a IF statement to determine if the registration code has been
inserted that i have not typed in above, so if the code is correct, the
user can save. if not, it doesnt let them.

Now, question: Would it be a good idea to terminate the program after
the user finds out they cannot save (as it presently does)
OR
Should the user get a chance to return to the main program menu where
they can use it more or chose to exit again? (this is what i would like
to do)

Does anyone know how to make the program re-run instead of exiting in
this situation?

Thank's again

~LocVez


--
LocVez
------------------------------------------------------------------------
LocVez's Profile:

http://www.excelforum.com/member.php...o&userid=24021
View this thread: http://www.excelforum.com/showthread...hreadid=376379





All times are GMT +1. The time now is 03:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com