Results 1 to 8 of 8
  1. #1
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Preventing headers from being edited (2000/XP)

    Anybody know how to create a header in a document and then lock it for editing?

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

    Re: Preventing headers from being edited (2000/XP)

    One way is to lock the document for forms. Create at least two sections in the document, and leave the appropriate sections unprotected. Unfortunately, protecting a document for forms disables much more than editing headers and footers alone.

    In a non-protected document, you can create a blank macro named ViewHeader. This will disable the View | Header and Footer menu option, but the user can still double click the header to activate it.

  3. #3
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Preventing headers from being edited (2000/XP)

    Thanks as always, Hans. I was looking into your second suggestion, and did an experiment that appeared to prevent the user from double-clicking on the header, by using the Application.WindowSelectionChange event. I'm not sure how far we're going to go with this, but here's a rough draft of the code:

    Private Sub MyApp_WindowSelectionChange(ByVal Sel As Selection)
    With Sel.Range
    If .InRange(rngHeader) Then ' rngHeader is the wdHeaderFooterPrimary header range
    OutputDebugString "in rngHeader"
    ThisDocument.Range(Start:=.End + 1, End:=.End + 1).Select
    End If
    End With
    End Sub

    Two questions: (1) What do you do if the select statement raises an error? and (2) Does handling the WindowSelectionChange event have a significant effect on performance?

    Dan

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

    Re: Preventing headers from being edited (2000/XP)

    You might put error handling in the macro, but I doubt whether this is a good approach. Your range rngHeader is just the header of one section. If your document consists of more sections, the code would become more complicated and might have a negative impact on performance. In a document with just one section you probably wouldn't notice the effect.

    With error handling, the code would look like this:

    Private Sub MyApp_WindowSelectionChange(ByVal Sel As Selection)
    On Error GoTo ErrHandler

    With Sel.Range
    If .InRange(rngHeader) Then ' rngHeader is the wdHeaderFooterPrimary header range
    OutputDebugString "in rngHeader"
    ThisDocument.Range(Start:=.End + 1, End:=.End + 1).Select
    End If
    End With
    Exit Sub

    ErrHandler:
    MsgBox "Error " & Err & ": " & Err.Description, vbExclamation
    End Sub

    Once you have an idea which errors occur, you could handle them individually in a Select Case ... End Select statement.

  5. #5
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Preventing headers from being edited (2000/XP)

    Thanks Hans. Do you have any idea whether handling WindowSelectionChange event will have an impact on performance (assuming you get in and out of the event fairly quickly)?

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

    Re: Preventing headers from being edited (2000/XP)

    I tried to answer that in my previous reply. If the code is short, you probably won't notice it. But if you have a document with lots of sections and different headers and footers, the code would have to do a lot of checking, so you might notice it.
    But why don't you test it yourself? Try the code in a copy of the most complicated document it is likely to be used for, in a "realistic" situation - have as many other applications and documents open as will likely be the case in real use, and on the slowest PC where it will be used.

  7. #7
    2 Star Lounger
    Join Date
    Sep 2002
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Preventing headers from being edited (2000/XP)

    Thanks again Hans. Sorry I didn't see the end of your previous reply. I'm a little fried here today. [img]/forums/images/smilies/smile.gif[/img]

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

    Re: Preventing headers from being edited (2000/XP)

    And it's not even friedday yet! <img src=/S/evilgrin.gif border=0 alt=evilgrin width=15 height=15>

Posting Permissions

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