From: April on
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
From: Graham Mayor on
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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>



"April" <April(a)discussions.microsoft.com> wrote in message
news:F49BD603-942F-4892-A216-FFE2E7C27173(a)microsoft.com...
>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


From: April on
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.

"Graham Mayor" wrote:

> 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?
>
> --