Preventing users from entering the header

A

April

I have the following code from the wonderful Bill Coan over at the MVPs site.
It's supposed to prevent users from editing the headers in the document. I've
got this code in the template. Problem is, it's set up for Word 97 but I'm
using 2007. It keeps crashing no the wdSeekMainDocument line toward the end.

I saw a post that said I should change the ThisDocument to ActiveDocument,
and I tried that, but that just made the code disappear altogether when I
created a document from the template this is in.

Any ideas?

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
 
G

Graham Mayor

I have just tested this with the code copied from your message into the
ThisDocument module of both a DOT and DOTM template in Word 2007 and it
works without error?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

April

Hmmm. Originally, it worked fine for me too. Now it doesn't. The only change
I made was to remove an Adobe COM add in.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top