#1   Report Post  
John
 
Posts: n/a
Default Macro Help

I asked a question yesterday about creating a macro that within it, removes
the protection from the worksheet, does what it is supposed to do, and then
puts the password back on. Someone reasponded with that is below, but
unfortunately that did not work.

I have two worksheets, so I don't know if that is causing the problem. The
macro is supposed to change the format of one cell in one worksheet, then go
to the other worksheet2, change that format to the same thing, then go back
to the original worksheet. Is this possible?

Sub UnProtectSheet()
PWD = "password"
Worksheets("sheet1").Unprotect Password:=PWD
End Sub




  #2   Report Post  
SongBear
 
Posts: n/a
Default

I just tried it in an empty spread sheet and it did work. Of course, it will
only work if your password is "password", otherwise you need to substitute
the actual password between the quotes.
What I used to protect and then un protect:

Sub ProtectSheet()
PWD = "password"
Worksheets("sheet1").Protect Password:=PWD
End Sub

Sub UnProtectSheet()
PWD = "password"
Worksheets("sheet1").Unprotect Password:=PWD
End Sub

I put this code in a module, not in the worksheet code page, but I have made
the same macro work in the sheet code page in the past.
I set it up like that so that I could call it from inside another (main)
sub. That way, when I was ready to modify the worksheet in the main sub, i
called the unprotect sub (with the correct password) and then modified the
worksheet, then called the protect sub to secure the worksheet again.
Bear

"John" wrote:

I asked a question yesterday about creating a macro that within it, removes
the protection from the worksheet, does what it is supposed to do, and then
puts the password back on. Someone reasponded with that is below, but
unfortunately that did not work.

I have two worksheets, so I don't know if that is causing the problem. The
macro is supposed to change the format of one cell in one worksheet, then go
to the other worksheet2, change that format to the same thing, then go back
to the original worksheet. Is this possible?

Sub UnProtectSheet()
PWD = "password"
Worksheets("sheet1").Unprotect Password:=PWD
End Sub




  #3   Report Post  
Zac
 
Posts: n/a
Default

I'm attempting a similar thing as John. All I want is when a user accesses
the spreadsheet and goes to his/her appropriate worksheet, the user can
remove protection then reapply protection using the same password once
they're done. Going to Tools/Protect Worksheet again means having to re-enter
another password. I want a macro that can reapply it easily. The UnProtect
portion of the macro mentioned in this post works fine, but the Protect sub
needs to prompt the user to enter a password, which I could not get it to do.
They simply protect/unprotect with no password involvement.

"John" wrote:

I asked a question yesterday about creating a macro that within it, removes
the protection from the worksheet, does what it is supposed to do, and then
puts the password back on. Someone reasponded with that is below, but
unfortunately that did not work.

I have two worksheets, so I don't know if that is causing the problem. The
macro is supposed to change the format of one cell in one worksheet, then go
to the other worksheet2, change that format to the same thing, then go back
to the original worksheet. Is this possible?

Sub UnProtectSheet()
PWD = "password"
Worksheets("sheet1").Unprotect Password:=PWD
End Sub




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
Help with macro formula and variable Huge project Excel Worksheet Functions 0 December 28th 04 01:27 AM
Zip Code Macro Ken Wright Excel Worksheet Functions 0 December 9th 04 07:55 AM
Macro and If Statement SATB Excel Discussion (Misc queries) 2 December 3rd 04 04:46 PM
Macro Formula revision? Mark Excel Worksheet Functions 1 November 28th 04 01:43 AM
Macro for multiple charts JS Excel Worksheet Functions 1 November 19th 04 03:44 AM


All times are GMT +1. The time now is 03:50 PM.

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

About Us

"It's about Microsoft Excel"