Loncat ke daftar isi utama

Bagaimana cara melindungi header dan footer di Excel?

Di Excel, kita dapat melindungi sel dengan cepat dan mudah, tetapi, pernahkah Anda mencoba melindungi header dan footer untuk mencegah orang lain memodifikasinya? Biasanya, tidak ada cara langsung untuk menyelesaikan tugas ini di lembar kerja, tetapi, kode VBA berikut mungkin membantu Anda.

Lindungi header dan footer dengan kode VBA


panah gelembung kanan biru Lindungi header dan footer dengan kode VBA

Header dan footer berguna untuk kita saat mencetak lembar kerja, agar tidak diubah oleh orang lain, lakukan dengan langkah-langkah berikut:

1. Tahan ALT + F11 kunci untuk membuka Microsoft Visual Basic untuk Aplikasi jendela.

2. Lalu klik dua kali Buku Kerja Ini bawah Proyek VBA bagian untuk membuka modul kosong, lalu salin dan tempel kode berikut ke dalam modul:

Kode VBA: Lindungi header dan footer

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 melindungi footer header 1

Note: Anda dapat memasukkan konten header atau footer ke lokasi yang sesuai pada kode di atas.

3. Dan kemudian simpan dan tutup kode ini, sekarang, sambil mengklik Save tombol untuk menyimpan buku kerja ini, konten header atau footer yang dimodifikasi akan dikembalikan ke aslinya secara otomatis jika Anda telah mencoba mengubah header atau footer, lihat tangkapan layar:

doc melindungi footer header 2

Alat Produktivitas Kantor Terbaik

馃 Kutools AI Ajudan: Merevolusi analisis data berdasarkan: Eksekusi Cerdas   |  Hasilkan Kode  |  Buat Rumus Khusus  |  Analisis Data dan Hasilkan Grafik  |  Aktifkan Fungsi Kutools...
Fitur Populer: Temukan, Sorot, atau Identifikasi Duplikat   |  Hapus Baris Kosong   |  Gabungkan Kolom atau Sel tanpa Kehilangan Data   |   Putaran tanpa Formula ...
Pencarian Super: VLookup Beberapa Kriteria    VLookup Nilai Berganda  |   VLookup di Beberapa Lembar   |   Pencarian Fuzzy ....
Daftar Drop-down Lanjutan: Buat Daftar Drop Down dengan Cepat   |  Daftar Drop Down yang Bergantung   |  Multi-pilih Drop Down List ....
Manajer Kolom: Tambahkan Jumlah Kolom Tertentu  |  Pindahkan Kolom  |  Alihkan Status Visibilitas Kolom Tersembunyi  |  Bandingkan Rentang & Kolom ...
Fitur Unggulan: Fokus Kisi   |  Tampilan Desain   |   Bar Formula Besar    Manajer Buku Kerja & Lembar   |  Perpustakaan Sumberdaya (Teks otomatis)   |  Pemetik tanggal   |  Gabungkan Lembar Kerja   |  Enkripsi/Dekripsi Sel    Kirim Email berdasarkan Daftar   |  Filter Super   |   Filter Khusus (filter tebal/miring/coret...) ...
15 Perangkat Teratas12 Teks Tools (Tambahkan Teks, Hapus Karakter, ...)   |   50 + Grafik jenis (Gantt Chart, ...)   |   40+ Praktis Rumus (Hitung usia berdasarkan ulang tahun, ...)   |   19 Insersi Tools (Masukkan Kode QR, Sisipkan Gambar dari Jalur, ...)   |   12 Konversi Tools (Angka ke Kata, Konversi Mata Uang, ...)   |   7 Gabungkan & Pisahkan Tools (Lanjutan Gabungkan Baris, Pisahkan Sel, ...)   |   ... dan banyak lagi

Tingkatkan Keterampilan Excel Anda dengan Kutools for Excel, dan Rasakan Efisiensi yang Belum Pernah Ada Sebelumnya. Kutools for Excel Menawarkan Lebih dari 300 Fitur Lanjutan untuk Meningkatkan Produktivitas dan Menghemat Waktu.  Klik Di Sini untuk Mendapatkan Fitur yang Paling Anda Butuhkan...

Deskripsi Produk


Tab Office Membawa antarmuka Tab ke Office, dan Membuat Pekerjaan Anda Jauh Lebih Mudah

  • Aktifkan pengeditan dan pembacaan tab di Word, Excel, PowerPoint, Publisher, Access, Visio, dan Project.
  • Buka dan buat banyak dokumen di tab baru di jendela yang sama, bukan di jendela baru.
  • Meningkatkan produktivitas Anda sebesar 50%, dan mengurangi ratusan klik mouse untuk Anda setiap hari!
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