Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / General Excel Questions / May 2007

Tip: Looking for answers? Try searching our database.

HELP!!!! Calling a sub from Workbook_BeforeSave

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RocketMan - 31 May 2007 18:42 GMT
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 - 31 May 2007 19:41 GMT
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
Signature

HTH...

Jim Thomlinson

> 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
[quoted text clipped - 3 lines]
>
> John
RocketMan - 31 May 2007 20:11 GMT
OPPS, I was in an add in (an .xla file) which I can see.
> 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
[quoted text clipped - 22 lines]
> >
> > John
Jim Thomlinson - 31 May 2007 21:58 GMT
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...
Signature

HTH...

Jim Thomlinson

> OPPS, I was in an add in (an .xla file) which I can see.
> > Assuming the module is in the spreadsheet and not in an addin or some other
[quoted text clipped - 23 lines]
> > >
> > > John
RocketMan - 31 May 2007 23:47 GMT
> 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.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.