シートを保護・保護したシートを解除する(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 |
関連記事
-
-
印刷設定(フッターに文字列を指定)LeftFooter,CenterFooter,RightFooter
PageSetup.LeftFooter プロパティ PageSetup.Lef …
-
-
枠線の表示・非表示の設定(DisplayGridlines プロパティ)
枠線の表示・非表示の設定 枠線の表示・非表示を設定するには、DisplayGri …
-
-
ユーザー設定のビュー(CustomView オブジェクト)
ユーザー設定のビュー CustomView オブジェクトは、登録されている各ビュ …
-
-
アウトライン記号の表示・非表示(DisplayOutline プロパティ)
アウトライン記号の表示・非表示(DisplayOutline プロパティ) Di …
-
-
ブックが共有モードか確認する(MultiUserEditing プロパティ)
ブックが共有モードか確認する(MultiUserEditing プロパティ) 共 …
-
-
ウィンドウのタイトル(Window.Caption プロパティ)
ウィンドウのタイトル(Caption プロパティ) Windows.Captio …
-
-
シートが保護されているか確認(ProtectContents プロパティ)
ProtectContents プロパティ ワークシートが保護されているかどうか …
-
-
印刷時、シート内のエラーをどう扱うかを設定(PrintErrors プロパティ)
PageSetup.PrintErrors プロパティ PageSetup.Pr …
-
-
行列の見出しの表示・非表示(DisplayHeadings プロパティ)
DisplayHeadings プロパティ 行と列の見出しの表示・非表示を設定お …
-
-
シート見出しの色を設定(Tab プロパティ)
シート見出しの色を設定 Tab オブジェクトの Color プロパティ、Colo …