Automatically run VB code on workbook save event

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

Is it possible to have the workbook save event trigger VB
code to run in Excel? I know you can do it in ACCESS. If
so, how would I do that?

Thanks.
 
Tim, do it like this, put in thisworkbook code

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
'your code here
End Sub

--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 97 & 2000
** remove news from my email address to reply by email **
 
Paul,

Thank you for the suggestion. I keep getting a fatal
error. It saves the csv, but then the actual save fails.
Unfortunately I think I need to run my code after save and
I did not see that as an event. Any ideas?

Here is my code:

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

Dim filename$
filename = "c:\daily manual trade totals1.csv"

ActiveWorkbook.SaveAs filename:=filename,
FileFormat:=xlCSV, CreateBackup:=False

End Sub
 
Back
Top