View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Doug Glancy Doug Glancy is offline
external usenet poster
 
Posts: 770
Default Workbook_beforesave question

Calgarychris,

I wonder if it's because you are using an Excel keyword, "Protect", as a
module name? You might try renaming, in any event it's recommended not to
name variables, etc. with Excel keywords.

hth,

Doug

"Calgarychris" wrote in message
...
Hi,

I've scanned the Q&As for this but I can't seem to get the beforesave
event
to work. All I want to do is, just before saving, a macro would protect
each
sheet in the spreadsheet. I can run that macro easily enough on its own,
but
when I call that sub from the beforesub it doesn't seem to fire...it
doesn't
even allow me to step through it.

Obviously I'm very very green at all this...I checked my
application.enableevents was true (I'm not even sure what that does!),
I've
checked that it's located in the Thisworkbook section...I can successfully
run a workbook_open event. I'm not sure if maybe I haven't declared
something correctly, or do I need to pass something to the save event???
Please help! Thanks!

The following is cut from my Thisworkbook section:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

Call protect

End Sub

Protect is as follows (in my Module 1):

Sub protect()

Dim wb As Workbook
Dim sh As Worksheet

Set wb = ThisWorkbook

Application.ScreenUpdating = False
For Each sh In wb.Worksheets
sh.protect Password:="xxxx", DrawingObjects:=True, Contents:=True,
Scenarios:=True
Next sh
Application.ScreenUpdating = True

End Sub



--
Thanks!