ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   HELP!!!! Calling a sub from Workbook_BeforeSave (https://www.excelbanter.com/excel-discussion-misc-queries/144732-help-calling-sub-workbook_beforesave.html)

RocketMan[_2_]

HELP!!!! Calling a sub from Workbook_BeforeSave
 
I have a sub called SSave in a module called SLOCSave which I would
like to call in private sub Workbook_BeforeSave but I can't figure out
how.

HELP

John


Jim Thomlinson

HELP!!!! Calling a sub from Workbook_BeforeSave
 
Assuming the module is in the spreadsheet and not in an addin or some other
spreadsheet then... (I am assuming that your procedure does a save and that
you do not need to worry about Save vs SaveAs)

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
on error goto ErrorHandler

Cancel = True 'Assuming you want to cancel the save done by the user
Application.enableevents = false 'Assuming your called procedure does a save
Call SLOCSave.SSave

ErrorHandler:
application.enableevents = true
End Sub
--
HTH...

Jim Thomlinson


"RocketMan" wrote:

I have a sub called SSave in a module called SLOCSave which I would
like to call in private sub Workbook_BeforeSave but I can't figure out
how.

HELP

John



RocketMan[_2_]

HELP!!!! Calling a sub from Workbook_BeforeSave
 
OPPS, I was in an add in (an .xla file) which I can see.
Jim Thomlinson wrote:
Assuming the module is in the spreadsheet and not in an addin or some other
spreadsheet then... (I am assuming that your procedure does a save and that
you do not need to worry about Save vs SaveAs)

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
on error goto ErrorHandler

Cancel = True 'Assuming you want to cancel the save done by the user
Application.enableevents = false 'Assuming your called procedure does a save
Call SLOCSave.SSave

ErrorHandler:
application.enableevents = true
End Sub
--
HTH...

Jim Thomlinson


"RocketMan" wrote:

I have a sub called SSave in a module called SLOCSave which I would
like to call in private sub Workbook_BeforeSave but I can't figure out
how.

HELP

John




Jim Thomlinson

HELP!!!! Calling a sub from Workbook_BeforeSave
 
Two possible methods...

1. Application.Run "Book1.xls!ThisWorkBook.MyExcelMacro"
2. Create a reference in your speadsheet to the Addin (Tools - References
- select your addin. this is a lote easier if you have named your addin
something other than the default VBAProject. Right click the addin project
and select properties and change the project name)

Option 2 is a bit more efficient than option 1 as it creates a direct
reference to the addin. That being said the code for your workbook will not
compile on any machine that does not have the addin installed. Option 1 has
the advantage of compiling (but it will thow an error if you try to execute
it) on a machine without the addin. Up to you which direction to go...
--
HTH...

Jim Thomlinson


"RocketMan" wrote:

OPPS, I was in an add in (an .xla file) which I can see.
Jim Thomlinson wrote:
Assuming the module is in the spreadsheet and not in an addin or some other
spreadsheet then... (I am assuming that your procedure does a save and that
you do not need to worry about Save vs SaveAs)

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
on error goto ErrorHandler

Cancel = True 'Assuming you want to cancel the save done by the user
Application.enableevents = false 'Assuming your called procedure does a save
Call SLOCSave.SSave

ErrorHandler:
application.enableevents = true
End Sub
--
HTH...

Jim Thomlinson


"RocketMan" wrote:

I have a sub called SSave in a module called SLOCSave which I would
like to call in private sub Workbook_BeforeSave but I can't figure out
how.

HELP

John





RocketMan[_2_]

HELP!!!! Calling a sub from Workbook_BeforeSave
 

Jim Thomlinson wrote:
Assuming the module is in the spreadsheet and not in an addin or some other
spreadsheet then...


OPPS forgot to say it was in another spreadsheet add in (.xla ) that I
did add and can see.



All times are GMT +1. The time now is 12:20 AM.

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