ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copying Protected Worksheet (https://www.excelbanter.com/excel-programming/339977-copying-protected-worksheet.html)

Karen

Copying Protected Worksheet
 
I have a macro that will copy one worksheet to a new one. My user wants
parts of the first worksheet protected (locked cells). When I try to run the
macro, it returns an error due to the protection. How do I write code to
unprotect the current worksheet so I can create a new one - and not have the
user enter the password??

Karen.....

Jim Thomlinson[_4_]

Copying Protected Worksheet
 
You can not copy a sheet in code that is protected (the same as you can not
copy it witout using code and just doing it manually). Why not unprotect it,
copy it and reprotect it?
--
HTH...

Jim Thomlinson


"Karen" wrote:

I have a macro that will copy one worksheet to a new one. My user wants
parts of the first worksheet protected (locked cells). When I try to run the
macro, it returns an error due to the protection. How do I write code to
unprotect the current worksheet so I can create a new one - and not have the
user enter the password??

Karen.....


Karen

Copying Protected Worksheet
 
Jin~ That is what I am trying to do within VBA code. I am struggling with
the protect, unprotect, and password codes needed to do this.

Any ideas?

"Jim Thomlinson" wrote:

You can not copy a sheet in code that is protected (the same as you can not
copy it witout using code and just doing it manually). Why not unprotect it,
copy it and reprotect it?
--
HTH...

Jim Thomlinson


"Karen" wrote:

I have a macro that will copy one worksheet to a new one. My user wants
parts of the first worksheet protected (locked cells). When I try to run the
macro, it returns an error due to the protection. How do I write code to
unprotect the current worksheet so I can create a new one - and not have the
user enter the password??

Karen.....


Dave Peterson

Copying Protected Worksheet
 
worksheets("sheet1").unprotect password:="hi"
'do the copy
worksheets("sheet1").protect password:="hi"

If you rightclick on the worksheet tab, you can Move or copy to a new location
(even a different workbook).

This kind of copying will keep the sheet protection.



Karen wrote:

I have a macro that will copy one worksheet to a new one. My user wants
parts of the first worksheet protected (locked cells). When I try to run the
macro, it returns an error due to the protection. How do I write code to
unprotect the current worksheet so I can create a new one - and not have the
user enter the password??

Karen.....


--

Dave Peterson


All times are GMT +1. The time now is 11:09 AM.

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