メインコンテンツへスキップ

Excelでヘッダーとフッターを保護する方法は?

Excelでは、セルをすばやく簡単に保護できますが、他のユーザーがセルを変更しないようにヘッダーとフッターを保護しようとしたことがありますか? 通常、ワークシートでこのタスクを直接解決する方法はありませんが、次のVBAコードを使用するとよい場合があります。

VBAコードでヘッダーとフッターを保護する


矢印青い右バブル VBAコードでヘッダーとフッターを保護する

ヘッダーとフッターは、ワークシートを印刷するときに役立ちます。他の人に変更されないようにするには、次の手順を実行してください。

1。 を押し続けます Alt + F11 キーを押して アプリケーション向け Microsoft Visual Basic 窓。

2。 次にダブルクリックします このワークブックVBAプロジェクト セクションを開いて空のモジュールを開き、次のコードをコピーしてモジュールに貼り付けます。

VBAコード:ヘッダーとフッターを保護する

Option Explicit
Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Call ProtectHF
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Call ProtectHF
End Sub
Private Sub Workbook_Open()
    Call ProtectHF
End Sub
Private Sub ProtectHF()
'Updateby Extendoffice
    Application.ScreenUpdating = False
    ThisWorkbook.ActiveSheet.PageSetup.RightHeader = ""
    ThisWorkbook.ActiveSheet.PageSetup.RightFooter = ""
    ThisWorkbook.ActiveSheet.PageSetup.CenterFooter = "KTE-Sale-Report"
    ThisWorkbook.ActiveSheet.PageSetup.CenterHeader = "Created by Skyyang"
    ThisWorkbook.ActiveSheet.PageSetup.LeftHeader = ""
    ThisWorkbook.ActiveSheet.PageSetup.LeftFooter = ""
    Application.ScreenUpdating = True
End Sub

docプロテクトヘッダーフッター1

Note:上記のコードの対応する場所にヘッダーまたはフッターのコンテンツを挿入できます。

3。 そして、クリックしながら、このコードを保存して閉じます Save このワークブックを保存するためのボタンをクリックすると、ヘッダーまたはフッターを変更しようとした場合、変更されたヘッダーまたはフッターのコンテンツが自動的に元のコンテンツに戻ります。スクリーンショットを参照してください。

docプロテクトヘッダーフッター2

最高のオフィス生産性向上ツール

🤖 Kutools AI アシスタント: 以下に基づいてデータ分析に革命をもたらします。 インテリジェントな実行   |  コードを生成  |  カスタム数式の作成  |  データを分析してグラフを生成する  |  Kutools関数を呼び出す...
人気の機能: 重複を検索、強調表示、または識別する   |  空白行を削除する   |  データを失わずに列またはセルを結合する   |   数式なしのラウンド ...
スーパールックアップ: 複数の基準の VLookup    複数の値の VLookup  |   複数のシートにわたる VLookup   |   ファジールックアップ ....
詳細ドロップダウン リスト: ドロップダウンリストを素早く作成する   |  依存関係のドロップダウン リスト   |  複数選択のドロップダウンリスト ....
列マネージャー: 特定の数の列を追加する  |  列の移動  |  Toggle 非表示列の表示ステータス  |  範囲と列の比較 ...
注目の機能: グリッドフォーカス   |  デザインビュー   |   ビッグフォーミュラバー    ワークブックとシートマネージャー   |  リソースライブラリ (自動テキスト)   |  日付ピッカー   |  ワークシートを組み合わせる   |  セルの暗号化/復号化    リストごとにメールを送信する   |  スーパーフィルター   |   特殊フィルター (太字/斜体/取り消し線をフィルター...) ...
上位 15 のツールセット12 テキスト ツール (テキストを追加, 文字を削除する、...)   |   50+ チャート 種類 (ガントチャート、...)   |   40+ 実用的 (誕生日に基づいて年齢を計算する、...)   |   19 挿入 ツール (QRコードを挿入, パスから画像を挿入、...)   |   12 変換 ツール (数字から言葉へ, 通貨の換算、...)   |   7 マージ&スプリット ツール (高度な結合行, 分割セル、...)   |   ... もっと

Kutools for Excel で Excel スキルを強化し、これまでにない効率を体験してください。 Kutools for Excelは、生産性を向上させ、時間を節約するための300以上の高度な機能を提供します。  最も必要な機能を入手するにはここをクリックしてください...

説明


Officeタブは、タブ付きのインターフェイスをOfficeにもたらし、作​​業をはるかに簡単にします

  • Word、Excel、PowerPointでタブ付きの編集と読み取りを有効にする、パブリッシャー、アクセス、Visioおよびプロジェクト。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を 50% 向上させ、毎日何百回もマウス クリックを減らすことができます!
Comments (8)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
J'aime beaucoup, mais ce n'Est qu'une semi-sécurité pour l'en-tête. Je peux modifier les en-tête et les pied de page et imprimer avec la modification. Comment je pourrais empêcher toute modification exactement comme avec la protection de la feuille ???
This comment was minimized by the moderator on the site
Hello, Michael,
In fact, when you print the worksheet, the header or footer are not changed. It just changes the display in the Print Preview.
Please try it again, thank you!
This comment was minimized by the moderator on the site
Posso inserir uma imagem no cabeçalho?

Porque o meu cabeçalho é o logotipo da empresa.

Obrigada!
This comment was minimized by the moderator on the site
After shutting down and reopening the excel file, the header/footer can still be deleted. So how to fix this? 
Thank you very much!
This comment was minimized by the moderator on the site
Hello, Tracy,When you close the workbook, you should save it as Excel Macro-Enabled Workbook format, this will save the code.Reopening this file next time, please click Enable Content button from the top of the formula bar to activate the code.Please try, hope it can help you!
This comment was minimized by the moderator on the site
notas: Puede insertar el contenido del encabezado o pie de página en la ubicación correspondiente en el código anterior.
No entiendo ese paso , por favor si pueden explicarme, lo agradecería.
This comment was minimized by the moderator on the site
Hi used this with auto sheet name, file location, and page number and when saving it requires you to click in each field to print correctly.
This comment was minimized by the moderator on the site
Hi, Love the code to protect the header and footer, is there a way to change the font size, style, and color in the code so it is always replaced with a larger font?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations