using alternative passwords to unprotect worksheets

truskawa

New Member
Joined
Jan 27, 2011
Messages
27
Hi all,

I'm writing a macro that among other things has to unprotect all worksheets.
Thing is I want it to work on two versions of files. each one has other password used for unprotecting.

So far I came up with this:

Private Sub Unprotect()

Application.ScreenUpdating = False

On Error Resume Next

For Each ws In ActiveWorkbook.Worksheets
If ws.ProtectContents = True And ws.Visible = xlSheetVisible Then
ws.Unprotect ("2010pass")
ws.Unprotect ("2011pass")
End If
Next ws

Application.ScreenUpdating = True

End Sub


It works, but I get the feeling it is not the best way to do this.
Does this code make macro slower if workbook has a lot of worksheets. Is there a better way to do this?

Any advice would be appreciated!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Thanks :)

Based on number of pots I trust your judgment ;)

I just thought there was some way of supplying two passwords instead of trying to unprotect each worksheet twice and getting error once.

But when I think about this more closely I guess if there was a way to do this excel would do it the same way "behind the scenes".

Either way thanks!
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,841
Members
452,948
Latest member
UsmanAli786

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
Back
Top