Preventing users from editing Header
Word 2000
The following code, pasted into the This Document module of a Word 2000 Template, will keep users out of the header and footer of documents based on that template.
For Word 97, click here
Option Explicit
'reserve memory for an application variable
Private WithEvents wdApp As Word.Application
Private Sub Document_New()
'assign Word to the application variable
If wdApp Is Nothing Then
Set wdApp = ThisDocument.Application
End If
End Sub
Private Sub Document_Open()
'assign Word to the application variable
If wdApp Is Nothing Then
Set wdApp = ThisDocument.Application
End If
End Sub
Private Sub wdApp_WindowSelectionChange(ByVal Sel As Selection)
'quit if active doc isn't attached to this template
If ActiveDocument.AttachedTemplate <> ThisDocument Then Exit Sub
'get out of the header/footer if we're in it
Select Case Sel.StoryType
Case wdEvenPagesFooterStory, wdEvenPagesHeaderStory, _
wdFirstPageFooterStory, wdFirstPageHeaderStory, _
wdPrimaryFooterStory, wdPrimaryHeaderStory
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Exit Sub
Case Else
End Select
End Sub
Word 97
The first question to ask yourself is why you think users might want to edit the Header?
If the answer is: so that they can update the title, version number, etc. - use Document Properties with appropriate fields in the Header, so that these values are automatically updated when appropriate. And/or write a macro, assigned to a prominent toolbar button, which updates the DocProperties or when required. And train the users to use your button.
If you prefer to use Document Variables to Document Properties, you can have your macro, assigned to a button, update the text in the Headers (using bookmarks), without using fields. Unfortunately you can't use DocVariable fields in a Header - Word will crash.
Similarly, if the answer is: in order to create a landscape header, write a macro which does this, assign it to a toolbar button, and train your users to use it
If you still need to protect the Header, there is no satisfactory solution in Word 97, but here are some unsatisfactory ones!
Step 1
Write a macro called ViewHeader. This will intercept the ViewHeader command.
Doesn't prevent the user opening the Header (or Footer) by double-clicking on it.
Step 2
If you put a continuous Section Break right at the beginning of the document, and protect the document for forms (with a password), clicking on the Sections button on the Protect dialog and unchecking Section 2, the header and footer will not be accessible.
Unless the document is a form, protecting even one section will make the entire document pretty much unusable. As well as the spellchecker, many of the items on the View, Insert, Format, Tools and Table menus are disabled, as well as most items on the Drawing, Database, Visual Basic and Picture toolbars. It is possible to re-enable the spellchecker with a macro, but the other lost features can't be recovered.
Step 3
Store the Header's contents (including any DocVariable of DocProperty fields) as an AutoText entry and reinsert it when the user prints (by writing a FilePrint and FilePrintDefault macro).
Clunky but works, although your macro would need to be fairly sophisticated to cope with all possibilities (landscape sections etc).
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext