ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Automatically run VB code on workbook save event (https://www.excelbanter.com/excel-programming/285040-automatically-run-vbulletin-code-workbook-save-event.html)

Tim[_32_]

Automatically run VB code on workbook save event
 
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.

Paul B[_7_]

Automatically run VB code on workbook save event
 
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 **

"Tim" wrote in message
...
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

Automatically run VB code on workbook save event
 
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


-----Original Message-----
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 **

"Tim" wrote in message
...
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.



.



All times are GMT +1. The time now is 06:51 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com