Run macro that contains a sub, priv sub, priv func and func

knigget

New Member
Joined
Aug 5, 2011
Messages
33
Hi All,

I have a thread open already which might possibly answer this for me but for the benefit of the search button here goes..

I have a workbook that has a macro that contains 1 x sub, 1 x private sub, 1 x private function and 1 x function. How can I get these all to run when I hit the save button?

I have tried
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
but this only runs a little bit of code. If I put it at the top, it doesn't work.

Any help would be appreciated.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
You could try calling the subs explicitly from the beforesave event handler
 
Upvote 0
Like this?
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Call sub1
Call sub2
etc
End Sub


How would I call private subs, private functions and functions?
 
Upvote 0
Ok, think I have it sorted..

The name of the overall macro is at the top of my code:
Code:
Sub Copy_To_Another_Workbook()

Underneath this is my other private subs, private functions, functions.

I realised that when I ran the macro from excel with the play button, I was specifying it to run "Sub Copy_To_Another_Workbook()" so why not try calling it?
So at the bottom of the code I simply added:

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Call Copy_To_Another_Workbook
End Sub

This runs all the code (subs, private subs, private functions, functions)when I click save or Ctrl S.

Job done
 
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,522
Members
452,923
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top