Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to protect a worksheet that has been automatically unprotected.

Status
Not open for further replies.

tuccokeith

Technical User
Dec 11, 2002
58
US
Hello,

The code below uses a commandbutton to open a protected worksheet, unprotect it, and then uses the autofilter to remove blank lines.

How can I adjust this code so that the protection can be automatically turned back on after the autofilter is invoked?

Private Sub CommandButton2_Click()
Const PW = "hipaa"
If CommandButton2.Caption = "Alt Address 1" Then
Workbooks("IndividualRightsDatabase.xls").Worksheets("Alt_Address1").Activate
Me.Unprotect PW
Selection.AutoFilter Field:=2, Criteria1:=&quot;<>&quot;
End If
End Sub
 
From the excel VBA Help:

ActiveWorkbook.Protect Password := &quot;drowssap&quot;

Protect Method


Protects a chart or worksheet (Syntax 1) or a workbook (Syntax 2) so that it cannot be modified.

Syntax 1

expression.Protect(Password, DrawingObjects, Contents, Scenarios, UserInterfaceOnly)

Syntax 2

expression.Protect(Password, Structure, Windows)

expression Required. An expression that returns a Chart or Worksheet object (Syntax 1) or a Workbook object (Syntax 2).

Password Optional Variant. A string that specifies a case-sensitive password for the sheet or workbook. If this argument is omitted, you can unprotect the sheet or workbook without using a password. Otherwise, you must specify the password to unprotect the sheet or workbook. If you forget the password, you cannot unprotect the sheet or workbook. It's a good idea to keep a list of your passwords and their corresponding document names in a safe place.

DrawingObjects Optional Variant. True to protect shapes. The default value is False.

Contents Optional Variant. True to protect contents. For a chart, this protects the entire chart. For a worksheet, this protects the individual cells. The default value is True.

Scenarios Optional Variant. True to protect scenarios. This argument is valid only for worksheets. The default value is True.

Structure Optional Variant. True to protect the structure of the workbook (the relative position of the sheets). The default value is False.

UserInterfaceOnly Optional Variant. True to protect the user interface, but not macros. If this argument is omitted, protection applies both to macros and to the user interface.

Windows Optional Variant. True to protect the workbook windows. If this argument is omitted, the windows aren’t protected.

Remarks

If you apply the Protect method with the UserInterfaceOnly argument set to True to a worksheet and then save the workbook, the entire worksheet (not just the interface) will be fully protected when you reopen the workbook. To unprotect the worksheet but re-enable user interface protection after the workbook is opened, you must again apply the Protect method with UserInterfaceOnly set to True.
Leslie
landrews@metrocourt.state.nm.us

There are 10 types of people in the world -
those who understand binary
and
those who don't!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top