シートを保護・保護したシートを解除する(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 |
関連記事
-
-
Excel を全画面表示(DisplayFullScreen プロパティ)
DisplayFullScreen プロパティ DisplayFullScree …
-
-
シート見出しの表示・非表示(DisplayWorkbookTabs プロパティ)
シート見出しの表示・非表示(DisplayWorkbookTabs プロパティ) …
-
-
印刷設定(ヘッダーに文字列を指定)LeftHeader,CenterHeader,RightHeader
PageSetup.LeftHeader プロパティ PageSetup.Lef …
-
-
スクロール範囲を限定(ScrollArea プロパティ)
ScrollArea プロパティ ScrollArea プロパティ にセル範囲を …
-
-
行列番号を含めて印刷(PageSetup.PrintHeadings プロパティ)
PageSetup.PrintHeadings プロパティ PageSetup. …
-
-
ユーザー設定のドキュメントプロパティ(CustomDocumentProperties プロパティ)
CustomDocumentProperties プロパティ ユーザー設定のドキ …
-
-
印刷のタイトル行、タイトル列を設定(PrintTitleRows,PrintTitleColumns)
PageSetup.PrintTitleRows プロパティ PageSetup …
-
-
枠線の表示・非表示の設定(DisplayGridlines プロパティ)
枠線の表示・非表示の設定 枠線の表示・非表示を設定するには、DisplayGri …
-
-
印刷の用紙サイズを設定(PageSetup.PaperSize プロパティ)
PageSetup.PaperSize プロパティ PageSetup.Pape …
-
-
シート見出しの色を設定(Tab プロパティ)
シート見出しの色を設定 Tab オブジェクトの Color プロパティ、Colo …