Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

WorkbookBeforeSave event

  Asked By: Egidius    Date: Oct 02    Category: MS Office    Views: 800
  

I am trying to trigger an action upon the user explicitly saving the current
workbook (RawMatDatabase.xls).

On many other occasions my code will open the workbook, write and read values,
and close the database workbook without saving.

I am having trouble with the format of the mentioned event in the VBE Help file.
What I want to say is:


'Activeworkbook = database workbook at this stage.

Upon WorkbookBeforeSave event (or something similar I can use)
Call Another_Procedure

'Continue with code

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Frank Butler     Answered On: Oct 02

Difficult to see what problems you'd be having. There is a before save
event that works fine.

You need to post your actual code.

Have you tried stepping through the code  to see where it fails?

However, are you talking about doing the save from VBA code? If so, I don't
think it will trigger  this event  from VBA, because you can simply write  the
code you want just before your save. If you like, you can call the before
save event subroutine from your code.

 
Answer #2    Answered By: Francis Riley     Answered On: Oct 02

Below my actual code. It was very simple in the end, but I will explain
what had me stumped:

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

On Error GoTo Workbook_BeforeSave_Error

ActiveWorkbook.SendMail Recipients:="email.address@...",
Subject:="Raw Mat Database"

On Error GoTo 0
Exit Sub

Workbook_BeforeSave_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in
procedure Workbook_BeforeSave of VBA Document ThisWorkbook"
End Sub

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

What I could not understand were the options in the command. Eventually
someone here at work showed me. Select ThisWorkbook in the VBE explorer,
select Workbook instead of General, select the BeforeSave command, add a
line of code, and viola!

 
Didn't find what you were looking for? Find more on WorkbookBeforeSave event Or get search suggestion and latest updates.