ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to get a macro to run that uses a protected sheet (https://www.excelbanter.com/excel-programming/345862-how-get-macro-run-uses-protected-sheet.html)

MPM

How to get a macro to run that uses a protected sheet
 
I would like to create some simple macros (e.g. selecting criteria within an
autofilter and then printing the result) but I would also like to protect the
sheet that contains the Autofiltered data.

When I turn protection on the macro fails.

Is there any way to run macros AND protect sheets?

Thanks

Jim Thomlinson[_4_]

How to get a macro to run that uses a protected sheet
 
In code you need to unprotect then execute your code and then reprotect.
There is no way around it...
--
HTH...

Jim Thomlinson


"MPM" wrote:

I would like to create some simple macros (e.g. selecting criteria within an
autofilter and then printing the result) but I would also like to protect the
sheet that contains the Autofiltered data.

When I turn protection on the macro fails.

Is there any way to run macros AND protect sheets?

Thanks


K Dales[_2_]

How to get a macro to run that uses a protected sheet
 
Have then macro turn protection off and then when done turn it back on:

Sub MyMacro()

Sheets("Sheet1").Unprotect
' Run the rest of your code here
Sheets("Sheet1").Protect

End Sub
--
- K Dales


"MPM" wrote:

I would like to create some simple macros (e.g. selecting criteria within an
autofilter and then printing the result) but I would also like to protect the
sheet that contains the Autofiltered data.

When I turn protection on the macro fails.

Is there any way to run macros AND protect sheets?

Thanks


Tom Ogilvy

How to get a macro to run that uses a protected sheet
 
Activesheet.Protect UserInterfaceOnly:=True
ActiveSheet.EnableAutofilter = True

the autofilter must already exists, but you can change the criteria.

In xl2002 and later, I believe you have to supply the password (if there is
one) when you do the Protect command.

--
Regards,
Tom Ogilvy


"MPM" wrote in message
...
I would like to create some simple macros (e.g. selecting criteria within

an
autofilter and then printing the result) but I would also like to protect

the
sheet that contains the Autofiltered data.

When I turn protection on the macro fails.

Is there any way to run macros AND protect sheets?

Thanks





All times are GMT +1. The time now is 06:49 AM.

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