Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Macro to test sheet and workbook protect and unprotect status.

All,

Just wanted to share what finally came out of the guidance I received
from this ng. Maybe this will help someone else. Feedback
appreciated.:

This macro can be run from personal.xls or your self-created
MacroBook. For this macro, the user can select a workbook and the code
generates a msgbox showing the sheetname and whether the sheet is
protected or unprotected. Another msgbox is used to show the protected/
unprotected status of the target workbook.
VR/
Lost



Sub ProtectedStatus()
Dim wks As Worksheet
Dim myList As String
NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls),
*.xls", Title:="Please select a file")
If NewFN = False Then
' They pressed Cancel
MsgBox "Stopping because you did not select a file"
Exit Sub
Else
On Error GoTo Erro
Workbooks.Open Filename:=NewFN
End If
Set oldbk = Workbooks.Open(Filename:=NewFN)
result = ""
For Each wks In ActiveWorkbook.Worksheets
myList = myList + wks.Name
myList = myList + " " + IIf(wks.ProtectContents, "is protected.", "is
NOT PROTECTED!") + vbCr
Next wks
MsgBox myList
X = False
If ActiveWorkbook.ProtectWindows Then X = True
If ActiveWorkbook.ProtectStructure Then X = True
If X = False Then
MsgBox "The workbook is NOT PROTECTED!"
Else
MsgBox "The workbook is protected."
End If
oldbk.Close savechanges:=False
Erro:

Select Case Err
Case 0
MsgBox "Macro completed successfully (or was cancelled by user)."
Case Else
MsgBox "There is something wrong: " & Chr(10) & _
Err & ": " & Err.Description
End Select

Err.Clear
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
Code to protect/unprotect a sheet using a macro with password FredH Excel Discussion (Misc queries) 5 October 23rd 07 04:49 PM
Can I use a Macro to unprotect a sheet in the workbook? [email protected] Excel Programming 5 July 20th 05 07:45 PM
Unprotect and Protect sheet within macro John F[_2_] Excel Programming 3 January 11th 05 04:49 PM
Unprotect and protect sheet in a macro Ola Sigurdh Excel Programming 1 September 28th 04 11:55 PM
Protect/Unprotect Sheet from Macro Nigel[_8_] Excel Programming 1 May 14th 04 05:55 PM


All times are GMT +1. The time now is 06:49 AM.

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

About Us

"It's about Microsoft Excel"