How can I have two subroutines in ThisWorkBook?

pteronaut

New Member
Joined
Aug 6, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I currently have a Workbook_Open subroutine in ThisWorkbook to force the workbook to open to the 1st sheet.

I want to add a BeforeSave subroutine to prevent saving by the pressing of Ctrl-S.

I can add both subroutines and they work.

However, the BeforeSave Subroutine does not get saved, no matter where I save it. (On my computer, or on my Onedrive where I share it with my co-workers)

Any help would be gratefully appreciated.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi & welcome to MrExcel.
Are you preventing people from doing a save as, or just preventing them from saving?
 
Upvote 0
Hi & welcome to MrExcel.
Are you preventing people from doing a save as, or just preventing them from saving?
Save As, (to prevent forking of a shared workbook) and Ctrl-S (to prevent accidental saving of volatile data)

I am hoping to combine these two subroutines:

VBA Code:
Private Sub Workbook_Open()
 
Worksheets("Example").Activate
 
End Sub
 
Upvote 0
In that case you will need to disable macros, or open excel in safe mode so that you can save the workbook with the code.
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0
Interestingly, I must have really screwed with my Trust settings, as the macros are still working if I disable Macros in Trust Center or starting in Safe Mode.
1628253221749.png

Only when I disable "Allow documents on a network to be trusted" are the macros disabled.
 
Upvote 0
If the file is in a trusted location, then macros will be enabled regardless of security settings.
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

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