View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
JBeaucaire[_141_] JBeaucaire[_141_] is offline
external usenet poster
 
Posts: 1
Default Determining if the user enabled macros


I would suggest a set of simple macros, all hidden.

One macro secretly password protects the whole thing:

Code:
--------------------
Private Sub ProtectBook()
ActiveWorkbook.Protect Password:="PASSWORD", Structu=True, Windows:=False
ActiveSheet.Protect Password:="PASSWORD", Contents:=True, Scenarios:=True
End Sub
--------------------


And another to Unprotect:

Code:
--------------------
Private Sub UnprotectBook()
ActiveWorkbook.UnProtect Password:="PASSWORD"
ActiveSheet.UnProtect Password:="PASSWORD"
End Sub
--------------------


Then use the Workbook_BeforeSave to do the work for you:

Code:
--------------------
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
ProtectBook
ThisWorkbook.Save
UnprotectBook
End Sub
--------------------


To just close, a Workbook_BeforeClose fixes the protection in place:

Code:
--------------------
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ProtectBook
End Sub

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

Structured properly, your saved book is protected, but he user can keep
using it because the protecting and unprotecting keeps occuring in the
background.

If they crash their program, they lose what they had anyway, the saved
version WILL still be usable and macros still working.


--
JBeaucaire
------------------------------------------------------------------------
JBeaucaire's Profile: http://www.thecodecage.com/forumz/member.php?userid=73
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=46287