Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PA PA is offline
external usenet poster
 
Posts: 101
Default Macro in a protected worksheet

One of our users has recorded two simple macros, one to apply a custom filter
and one to remove the filter. It is required that the worksheet cells with
formulas be protected, and they are scattered over a broad range.
When protected, the macros will not run. Security is set to medium, and
both of the Trusted Sources check boxes are check.

Is there a workaround for this behaviour?

Thanks for any suggestions
Paul
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Macro in a protected worksheet

Hi Paul,
If the macros run but then produce an error then you should be able to
get them to work by including a line of code that unprotects the sheet.
This line will have to come before any other code lines that attempt to
change the sheet. If the protection was applied without a password then
just use...

ActiveSheet.Unprotect

If password eg 123 was used then use..

ActiveSheet.Unprotect(123)


After the macro code has done all its changes to the sheet the code can
reinstate the protection with the final line..

ActiveSheet.Protect 'if no password OR...

ActiveSheet.Protect(123) 'if password is 123

Ken Johnson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro in a protected worksheet


You can unprotected sheet and protect sheet in the macro

ActiveSheet.Unprotect
'your code here
ActiveSheet.Protect


--
davesexcel


------------------------------------------------------------------------
davesexcel's Profile: http://www.excelforum.com/member.php...o&userid=31708
View this thread: http://www.excelforum.com/showthread...hreadid=535754

  #4   Report Post  
Posted to microsoft.public.excel.programming
PA PA is offline
external usenet poster
 
Posts: 101
Default Macro in a protected worksheet

Perfect, thank you.

"Ken Johnson" wrote:

Hi Paul,
If the macros run but then produce an error then you should be able to
get them to work by including a line of code that unprotects the sheet.
This line will have to come before any other code lines that attempt to
change the sheet. If the protection was applied without a password then
just use...

ActiveSheet.Unprotect

If password eg 123 was used then use..

ActiveSheet.Unprotect(123)


After the macro code has done all its changes to the sheet the code can
reinstate the protection with the final line..

ActiveSheet.Protect 'if no password OR...

ActiveSheet.Protect(123) 'if password is 123

Ken Johnson


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default Macro in a protected worksheet

You're welcome Paul.
Thanks for the feedback.

Ken Johnson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro error when worksheet is protected Soroya1920 Excel Discussion (Misc queries) 2 August 27th 07 06:42 PM
How to run Macro functionality for a protected worksheet aflriwanna Excel Programming 2 March 10th 06 10:11 PM
Macro fails when worksheet protected George Tattam Excel Discussion (Misc queries) 5 February 9th 06 11:07 PM
How can I run a macro in a protected worksheet? Husker87 Excel Worksheet Functions 2 March 30th 05 11:14 PM
Protected worksheet and macro Massimiliano Alberti Excel Programming 1 October 30th 03 01:00 PM


All times are GMT +1. The time now is 05:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"