シートを保護・保護したシートを解除する(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 |
関連記事
-
-
印刷設定(ヘッダー・フッターに画像を設定)Graphic オブジェクト
Graphic オブジェクト Graphic オブジェクト は、ヘッダーおよびフ …
-
-
ワークシートにクリップボードの内容を貼り付ける(Paste メソッド)
Paste メソッド 指定したワークシート上にクリップボードのデータを貼り付けま …
-
-
表示されているセル範囲を取得(VisibleRange プロパティ)
VisibleRange プロパティ 現在表示されているセル範囲(Range オ …
-
-
ブックの表示を変更(View プロパティ)
ブックの表示を変更(View プロパティ) View プロパティ で、ブックの表 …
-
-
印刷設定(ページごとに異なるヘッダー・フッターを設定)Page オブジェクト・HeaderFooter オブジェクト
Page オブジェクト ページごとに異なるヘッダーおよびフッターを設定する場合、 …
-
-
印刷位置を中央に設定(CenterHorizontally, CenterVertically)
PageSetup.CenterHorizontally プロパティ PageS …
-
-
行列の見出しの表示・非表示(DisplayHeadings プロパティ)
DisplayHeadings プロパティ 行と列の見出しの表示・非表示を設定お …
-
-
ウィンドウの状態を取得・設定(WindowState プロパティ)
ウィンドウの状態を取得・設定(WindowState プロパティ) Window …
-
-
印刷設定(フッターに文字列を指定)LeftFooter,CenterFooter,RightFooter
PageSetup.LeftFooter プロパティ PageSetup.Lef …
-
-
ブックを保存する(Save メソッド)
ブックを保存する(Save メソッド) 既存のブックを上書き保存するには、Sav …