Creating Macro to Unprotect and unhide

M

Mandy

Hi,

I am not very technically minded but I am trying to create a macro to
unprotect a workbook and then unhide hidden worksheets. The workbook is
password protected so only certain users with the password should be able to
execute this macro. Any assistance with how I should do this would be
apprciated.

Mandy
 
J

Jim Rech

Why don't you post the code you have so far? If you have none using the
macro recorder is a good way to start.

--
Jim
| Hi,
|
| I am not very technically minded but I am trying to create a macro to
| unprotect a workbook and then unhide hidden worksheets. The workbook is
| password protected so only certain users with the password should be able
to
| execute this macro. Any assistance with how I should do this would be
| apprciated.
|
| Mandy
 
D

Dave Peterson

First, be aware that the workbook protection (tools|protection|protect workbook
in xl2003 menus) is easily broken. So if you have information that you don't
want anyone to see, then don't trust this kind of protection. Same with
worksheet protection, too.

Second, you could try this code:

Option Explicit
Sub testme()

Dim sh As Object

If ActiveWorkbook.ProtectStructure = True _
Or ActiveWorkbook.ProtectWindows = True Then
On Error Resume Next
Application.Dialogs(xlDialogWorkbookProtect).Show
If Err.Number <> 0 Then
Err.Clear
MsgBox "You don't know the password--I'm quitting!"
Exit Sub
End If
End If

For Each sh In ActiveWorkbook.Sheets
sh.Visible = xlSheetVisible
Next

End Sub

If you're new to macros:

Debra Dalgleish has some notes how to implement macros here:
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)
 

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