シートを保護・保護したシートを解除する(Protect メソッド・Unprotect メソッド)
2015/08/26
Protect メソッド・Unprotect メソッド
Protect メソッドは、対象のワークシート(Worksheet オブジェクト)を保護し、引数なしで実行した場合、Excel の [校閲] – [シートの保護] で、表示される「シートの保護」ダイアログボックスの設定にしたがってワークシートを保護します。
Unprotect メソッドは、ワークシートが保護されている場合は保護を解除し、保護されていない場合は無視されます。
<ワークシートを保護>
Object.Protect ( [ Password, DrawingObjects, Contents, Scenarios, UserInterfaceOnly, AllowFormattingCells, AllowFormattingColumns, AllowFormattingRows, AllowInsertingColumns, AllowInsertingRows, AllowInsertingHyperlinks, AllowDeletingColumns, AllowDeletingRows, AllowSorting, AllowFiltering, AllowUsingPivotTables ] )
<保護を解除>
Object.Unprotect ( [ Password ] )
引数・戻り値
| 引数 | 省略 | 型 | 内容 |
| Password | 可 | Variant | パスワード文字列を指定(大文字と小文字は、区別される)。省略時は、解除のときパスワードは不要となる。 |
| DrawingObjects | 可 | Variant | 図形の操作を許可する( True )既定値は、True。 |
| Contents | 可 | Variant | ロックされたセルを保護する( True )既定値は、True。 |
| Scenarios | 可 | Variant | シナリオの編集を許可する( True )既定値は、True。 |
| UserInterfaceOnly | 可 | Variant | マクロを使用した変更を許可する( True )。省略時は、マクロと通常操作の両方とも保護。 |
| AllowFormattingCells | 可 | Variant | セルの書式設定の変更を許可する( True )既定値は、False。 |
| AllowFormattingColumns | 可 | Variant | 列の書式設定の変更を許可する( True )既定値は、False。 |
| AllowFormattingRows | 可 | Variant | 行の書式設定の変更を許可する( True )既定値は、False。 |
| AllowInsertingColumns | 可 | Variant | 列の挿入を許可する( True )既定値は、False。 |
| AllowInsertingRows | 可 | Variant | 行の挿入を許可する( True )既定値は、False。 |
| AllowInsertingHyperlinks | 可 | Variant | ハイパーリンクの挿入を許可する( True )既定値は、False。 |
| AllowDeletingColumns | 可 | Variant | 列の削除を許可する( True )既定値は、False。 |
| AllowDeletingRows | 可 | Variant | 行の削除を許可する( True )既定値は、False。 |
| AllowSorting | 可 | Variant | 並べ替えの操作を許可する( True )既定値は、False。 |
| AllowFiltering | 可 | Variant | オートフィルタの操作を許可する( True )既定値は、False。 |
| AllowUsingPivotTables | 可 | Variant | ピボットテーブル、レポートの操作を許可する( True )既定値は、False。 |
Protect メソッド・Unprotect メソッドは、Chart オブジェクト(グラフシート)やWorkbook オブジェクト(ブック)を対象オブジェクトとして指定することもできます(ただし、引数は異なります)。
⇒ ブックを保護・保護を解除(Protect メソッド・Unprotect メソッド) を参照
⇒ グラフを保護・保護を解除(Protect メソッド・Unprotect メソッド) を参照
Protect メソッド・Unprotect メソッド 使用例
サンプルVBAソース
|
1 2 3 4 5 6 7 8 9 10 11 12 |
Sub Sample_Protect() 'ワークシートを保護(パスワード付き) ActiveSheet.Protect Password:="12345abcde" '保護を解除 ActiveSheet.Unprotect Password:="12345abcde" End Sub |
関連記事
-
-
ワークシートの追加・削除(Add メソッド・Delete メソッド)
新しいワークシートを作成 Add メソッドで、新しいワークシートを指定した場所に …
-
-
ワークシートを参照する(Worksheets プロパティ)
Worksheets プロパティ Worksheets プロパティは、Works …
-
-
印刷のタイトル行、タイトル列を設定(PrintTitleRows,PrintTitleColumns)
PageSetup.PrintTitleRows プロパティ PageSetup …
-
-
ブックのプロパティ(BuiltinDocumentProperties プロパティ)
BuiltinDocumentProperties プロパティ ブックのプロパテ …
-
-
指定したセル範囲が含まれるワークシートを参照する(Worksheet プロパティ)
Worksheet プロパティ Worksheet プロパティは、指定したセル範 …
-
-
印刷設定(フッターに文字列を指定)LeftFooter,CenterFooter,RightFooter
PageSetup.LeftFooter プロパティ PageSetup.Lef …
-
-
印刷設定(ヘッダー/フッター)書式コード・VBAコード
印刷設定(ヘッダー/フッター)書式コード・VBAコード ヘッダーおよびフッター( …
-
-
ワークシートの非表示・再表示(Visible プロパティ)
ワークシートの表示・非表示 ワークシートを非表示にしたり、非表示にしたワークシー …
-
-
印刷する用紙の向きを設定(PageSetup.Orientation プロパティ)
PageSetup.Orientation プロパティ PageSetup.Or …
-
-
印刷品質を設定(PageSetup.PrintQuality プロパティ)
PageSetup.PrintQuality プロパティ PageSetup.P …