A required expression that returns a Worksheet object. A string that specifies a case-sensitive password for the worksheet or workbook. If this argument is omitted, you can unprotect the worksheet or workbook without using a password. When set to True, this parameter protects drawing objects from changes.

Using Barcode maker for Software Control to generate, create GS1 128 image in Software applications.

www.OnBarcode.com

Part 3: The Excel Object Model

Microsoft Office Excel 2003 Programming Inside Out

Table 7-7.

7

Parameters of the Worksheet.Protect Method (continued)

Default

True

Parameter

Contents

Description

When set to True, protecting the contents of a worksheet protects any locked cells from changes. When set to True, the user cannot make changes to scenarios. When set to True, the user interface is protected, but the user can edit macros. When left blank or set to False, both the user interface and macros are protected. When set to True, users can format any cell on a protected worksheet. When set to True, users can format any column on a protected worksheet. When set to True, users can format any row on a protected worksheet. When set to True, users can insert columns into the protected worksheet. When set to True, users can insert rows into the protected worksheet. When set to True, users can add hyperlinks to a protected worksheet. When set to True, users can delete columns on the protected worksheet, provided every cell in the column to be deleted is unlocked. When set to True, users can delete rows on the protected worksheet, provided every cell in the row to be deleted is unlocked. When set to True, users can sort the data on the protected worksheet, provided every cell in the sort range is unlocked or unprotected. When set to True, users can set filters on the protected worksheet and change filter criteria but can t enable or disable an auto filter. When set to True, users can use PivotTables on the protected worksheet.

Workbooks and Worksheets Another way you can extend a worksheet s protection is to limit which cells the user can select by assigning a value to the EnableSelection property. After you protect a worksheet, you can set the EnableSelection property to any of the following Excel constants:

xlNoSelection, which prevents the user from selecting any cells on the sheet xlUnlockedCells, which allows the user to select only those cells whose Locked property

is set to False

xlNoRestrictions, the default value, which allows the user to select any value

The following code snippet prevents users from selecting any cells on the protected January worksheet:

Worksheets("January").EnableSelection = xlNoSelection

Important

protected.

Setting the EnableSelection property has an effect only if the worksheet is

As with a workbook, you can allow a user to unprotect a worksheet by providing the password. The line of code you use is simply this:

ActiveWorksheet. Unprotect

Excel displays an input box to accept the password for you, so you don t even have to write any additional code to handle the entry.

SaveAs Method

Just as you can save a workbook under a different name or to a different location, you can save an individual worksheet as a separate file using the Worksheet method s SaveAs method.

The SaveAs method of the Worksheet object is very similar to the same method of the Workbook object, so you can refer to Table 7-3 for details on most of the parameters of the Worksheet object s SaveAs method.

Select Method

At first glance the Select method seems to be the same as the Activate method. The difference between the two methods is that the Activate method only works on one worksheet at a time, whereas the Select method lets you operate on more than one worksheet at a time. As an example using the user interface, you can move two worksheets at a time by clicking the sheet tab of the first worksheet, shift-clicking the second sheet tab, and dragging the sheets as a unit to their new position in the workbook.