Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Jun 2001
    Location
    York, Pennsylvania, USA
    Posts
    164
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Locking header/footer (Word XP SP2)

    My company has a number of templates with different letterheads. They'd like me to add code so that changing the header and/or footer is disabled. Same with page setup. I got these tasks done, but not correctly, it seems. Occasionally a user will find that the above disablements have migrated over to their normal template, much to my chagrin. Does anyone have some code or a method that is bulletproof? I guess telling the users not to change anything is simply not elegant enough.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Locking header/footer (Word XP SP2)

    You don't say how you did this, so it's impossible to comment on it.

    How secure do you want to be? If you put a blank macro named ViewHeader in a module in the template, it will effectively disable the View | Header and Footer menu item. Users can still double click a header however, and edit it. A blank macro named FilePageSetup will disable the File | Page Setup menu item.

  3. #3
    2 Star Lounger
    Join Date
    Jun 2001
    Location
    York, Pennsylvania, USA
    Posts
    164
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Re: Locking header/footer (Word XP SP2)

    Hi Hans,

    Most of the users don't have a problem. However, the problem seems to be workstation specific. Everyone's running the same version of Word. They're all using 'File' ==> 'New' to create a document based on the template which contains the code below.

    Here's how I did it:

    Option Explicit

    Private WithEvents wdApp As Word.Application

    Private Sub Document_New()

    If wdApp Is Nothing Then
    Set wdApp = ThisDocument.Application
    End If
    CommandBars("File").Controls("Page Setup...").Enabled = False
    Templates(1).Saved = True

    End Sub

    Private Sub Document_Open()

    If wdApp Is Nothing Then
    Set wdApp = ThisDocument.Application
    End If
    CommandBars("File").Controls("Page Setup...").Enabled = False
    Templates(1).Saved = True

    End Sub

    Private Sub Document_Close()

    CommandBars("File").Controls("Page Setup...").Enabled = True
    Templates(1).Saved = True

    End Sub

    Private Sub wdApp_WindowSelectionChange(ByVal Sel As Selection)

    If ActiveDocument.AttachedTemplate <> ThisDocument Then
    Exit Sub
    End If

    On Error GoTo GetOut
    Select Case Sel.StoryType
    Case wdEvenPagesFooterStory, wdEvenPagesHeaderStory, _
    wdFirstPageFooterStory, wdFirstPageHeaderStory, _
    wdPrimaryFooterStory, wdPrimaryHeaderStory
    ActiveDocument.ActiveWindow.View.SeekView = wdSeekMainDocument
    Case Else
    End Select
    Exit Sub

    GetOut:
    Exit Sub

    End Sub

    Private Sub WdApp_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)

    CommandBars("File").Controls("Page Setup...").Enabled = True
    Templates(1).Saved = True
    Exit Sub

    End Sub

    The indenting seems to get blown away when I post, sorry.

    I think I covered all the document actions :>) But I guess not :>(

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Locking header/footer (Word XP SP2)

    The code for disabling File | Page Setup has the disadvantage that if execution of code is halted due to some kind of error (which need not have to do anything with your code), the item will not be enabled again when the document is closed. To prevent the modification from being stored in Normal.dot, insert the following line above the line that disables the menu item:

    CustomizationContext = ThisDocument

    Using a blank macro named FilePageSetup is easier, although it doesn't give the user a visual clue.

    The code to disable activating the header or footer should not survive quitting Word (you have a problem here if you use Word as e-mail editor in Outlook, for Outlook will keep Word open).

  5. #5
    2 Star Lounger
    Join Date
    Jun 2001
    Location
    York, Pennsylvania, USA
    Posts
    164
    Thanks
    0
    Thanked 3 Times in 2 Posts

    Re: Locking header/footer (Word XP SP2)

    Good deal, Hans. Somewhere along the line I missed learning about 'CustomizationContext = ThisDocument'.

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •