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