Referencing macro in add-in or from another sheet

BoilerBob

Board Regular
Joined
Apr 10, 2006
Messages
98
Thanks to various posts on the board, I have the following code that will protect all sheets in my workbook: :biggrin:
------------------------------------------------------------------------------------
Sub ProtectAllSheets()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Protect DrawingObjects:=True, AllowInsertingRows _
:=True, AllowFiltering:=True, Password:="password"
ActiveSheet.EnableSelection = xlNoRestrictions
Next ws
End Sub
-------------------------------------------------------------------------------------

I would like to use the above via add-in or personal.xls so that when I open a new workbook, I can protect all the sheets in the new workbook without copying and pasting the module into every new workbook.

When I put in personal.xls, I can run the macro but it only works on the personal.xls workbook.

When I load as an add-in, I do not 'see' the macro to reference it. I think this is the way to go, but need insights on how to work with add-ins.

Thanks...
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

acw

MrExcel MVP
Joined
Feb 13, 2004
Messages
4,814
Hi

You can leave it in your personal.xls but change

thisworkbook.worksheets

to

activeworkbook.worksheets


Tony
 

BoilerBob

Board Regular
Joined
Apr 10, 2006
Messages
98
Danka, Gracias, Thanks, and well done mate... Worked great.

I will continue with my education on add-ins...
 

Forum statistics

Threads
1,141,626
Messages
5,707,486
Members
421,510
Latest member
haroonstr

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
Top