Aug 18 2022 08:55 PM
Hi everyone,
Excel has headers and footers via PageLayout -> PageSetup ->Header/Footer. How do I lock and protect from changes using passwords?
Thanks in advance!
Aug 18 2022 09:19 PM
As far as I know a solution without VBA is not possible, since the user always has access to the toolbars.
The only thing I can think of is a small macro (VBA) that starts automatically before printing and fills the header and footer with the desired text.
Here is a small example with VBA
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Me.Unprotect("1234")
With ActiveSheet.PageSetup
.LeftHeader = "YourText1"
.CenterHeader = "YourText2"
.RightHeader="&D"'---date here
.LeftFooter = "YourText3"
.CenterFooter = "Page &P of &N pages" '--- Page number here
.RightFooter = "YourText4"
End With
Me.Protect("1234")
end sub
Hope I was able to help you with this info.
I know I don't know anything (Socrates)
Aug 18 2022 10:07 PM
Thx @NikolinoDE.
The problem I have is that both header and footer have images. Most solutions I've seen are about text-based content. Any idea how to do it reliably with images?
Aug 20 2022 05:35 AM
this should be adjusted and built into the worksheet, not the workbook.
Option Explicit
Private SubWorksheet_Activate()
Me.Unprotect ("1234")
ActiveSheet.PageSetup.LeftHeaderPicture.Filename = "C:\Documents and Settings\Nikolino\My Documents\My Pictures\MySelfFoto1.jpg"
ActiveSheet.PageSetup.RightHeaderPicture.Filename = "C:\Documents and Settings\Nikolino\My Documents\My Pictures\MySelfFoto2.jpg"
With ActiveSheet.PageSetup
.LeftHeader = "&G"
.CenterHeader = "Here the text for center header"
.RightHeader = "&G"
End With
Me.Protect ("1234")
End Sub
Aug 21 2022 05:54 AM