Multiple tabs

E

EMN

I would like to run a macro to unprotect several worksheets. I would like
the user to select the worksheets that need to be unprotected and run the
macro to unprotect them.

Sub test()
'
' test Macro
'
ActiveSheet.Unprotect
End Sub

How do I make ActiveSheet the selected sheets?

Thank you !!!!!!
 
T

Tom Hutchins

Try this:

Sub UnprotectSelectedSheets()
Dim sh As Worksheet, shts
On Error Resume Next
Set shts = ThisWorkbook.Windows(1).SelectedSheets
For Each sh In shts
sh.Select
ActiveSheet.Unprotect
Next
Set shts = Nothing
End Sub

You will have to modify the Unprotect statement if the sheets are password
protected.

Hope this helps,

Hutch
 
E

EMN

Thank you for responding, Tom. This did not work for me. When multiple
sheets are selected, it does not unprotect any of them. When the macro is
run with only one sheet selected, it unprotects the one sheet. There is no
password protection. Any thoughts?
 
T

Tom Hutchins

Are you trying to unprotect the sheets in a different workbook? The macro, as
written, works only on selected sheets in the same workbook where the macro
is stored. It would also unprotect the active sheet in another workbook
because of the ActiveSheet.Unprotect statement. Try changing this line:

Set shts = ThisWorkbook.Windows(1).SelectedSheets

to this:

Set shts = ActiveWorkbook.Windows(1).SelectedSheets

Hutch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top