View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Determining if the user enabled macros

It will depend on the users whether the previous answers will work
satisfactorily.

If protection is inserted in a Workbook_BeforeSave event then if the user
decides to periodically save their work (which is good practice) then
immediately they save they are locked out of doing any more work until they
close and re-open.

If protection code is inserted in just the Workbook_BeforeClose (without the
Workbook_BeforeSave) then the workbook must be saved again before the
protection takes effect so if you have a smart user then all they have to do
is save the workbook then close it and at the prompt to save they just answer
No and it will close without the protection.

If you include Save code in the Workbook_BeforeClose event to overcome the
above then you are treading dangerous ground. If a user messes up (and it
happens) and they want to close the workbook without saving then they can't
do it.

I am not saying don't use the the suggestions that have been provided; just
be aware of their linitations.

--
Regards,

OssieMac


"Simon Lloyd" wrote:


You will need to protect both the worksheet(s) and workbook structure
like this:

Code:
--------------------
ActiveWorkbook.Protect Password:="PASSWORD", Structu=True, Windows:=False
ActiveSheet.Protect Password:="PASSWORD", Contents:=True, Scenarios:=True
--------------------
Substitute PASSWORD for whatever password you wish, just amend the code
for UnProtect.JBeaucaire;167068 Wrote:
Create a Workbook_BeforeSave and a Workbook_Close macro that protects
the sheet completely from any changes.

Then put in a Workbook_Open macro to unprotect the sheet automatically.

Since the protection is occuring in the background, only clicking on
ENABLE MACROS will present the user with a sheet that can be edited
since the Workbook_Open event won't run and unprotect it without macros
being enabled.

Also, once you've done this, be sure to password protect the code in
the VBE, too, so they can't read the code without a password, perhaps
the same one you're protecting and unprotecting with in the background.



--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=46287