workbook beforesave event

J

JMCS

I am having problems getting this event to kick in. I need to intercept any
attempt to use the File Save menu or icon to make sure that the user's name
is captured (I do that on the Workbook Close event). I have just tried the
Help sample code (below) but cannot get that to work. Any ideas, please?

Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, _
ByVal SaveAsUI As Boolean, Cancel as Boolean)
a = MsgBox("Do you really want to save the workbook?", vbYesNo)
If a = vbNo Then Cancel = True
End Sub


JMCS
 
J

Joel

It needs to be in THISWORKBOOK module of the VBA code.

Books event are in Thisworkbook
Sheet events must match the sheet in the worksheet where you want the event
to occur.
 
J

JMCS

First of all many thanks for the quick response. However, that is where it
is in both my 'real' file and the 'test the beforesave event only' file. In
my 'real' file I have a beforeclose event and that works like a treat.

Regards
JMCS
 
P

Patrick Molloy

the procedure name you use,"App_WorkbookBeforeSave", isn't event driven
afaik. Use the workbook event...

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

IF MsgBox("Do you really want to save the workbook?", vbYesNo)=vbNo Then
Cancel = True
END IF

End Sub
 
J

JMCS

Joel was right, but my mistake was simply copying and pasting the Help code.
Reworking it got it to do what was required.
 

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