Header Protection in Word 2007

W

Word_2007_SASS

We currently have a number of templates that contain the following code under
"ThisDocument" to kick users out of the header when they try to access it.

---
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 Selection.StoryType
Case wdEvenPagesFooterStory, wdEvenPagesHeaderStory, _
wdFirstPageFooterStory, wdFirstPageHeaderStory, _
wdPrimaryFooterStory, wdPrimaryHeaderStory

ActiveDocument.Bookmarks("DocNum").Select
Selection.HomeKey Unit:=wdStory, Extend:=wdMove

Exit Sub
Case Else
End Select

End Sub
---

The code works when the template is run initially, however when a macro to
update the headers with new information is run but then cancelled using the
Cancel command or UserForm_QueryClose buttons (see below), the "ThisDocument"
code no longer applies to the document.

---
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)

If CloseMode = 0 Then
Me.Hide
Selection.HomeKey Unit:=wdStory, Extend:=wdMove
ActiveWindow.View.Type = wdPrintView
Application.ScreenUpdating = True
End If

End

End Sub
---
Private Sub cmdCancel_Click()

Me.Hide
Selection.HomeKey Unit:=wdStory, Extend:=wdMove
ActiveWindow.View.Type = wdPrintView
Application.ScreenUpdating = True

End

End Sub
---

Any ideas why this could be happening? We think it may be that the End
statement just stops everything and negates the ThisDocument code. Is there
an available alternative that will keep the ThisDocument code intact?

Any help is appreciated! Thanks!
 
F

Fumei2 via OfficeKB.com

why are you even using End?


Word_2007_SASS said:
We currently have a number of templates that contain the following code under
"ThisDocument" to kick users out of the header when they try to access it.

---
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 Selection.StoryType
Case wdEvenPagesFooterStory, wdEvenPagesHeaderStory, _
wdFirstPageFooterStory, wdFirstPageHeaderStory, _
wdPrimaryFooterStory, wdPrimaryHeaderStory

ActiveDocument.Bookmarks("DocNum").Select
Selection.HomeKey Unit:=wdStory, Extend:=wdMove

Exit Sub
Case Else
End Select

End Sub
---

The code works when the template is run initially, however when a macro to
update the headers with new information is run but then cancelled using the
Cancel command or UserForm_QueryClose buttons (see below), the "ThisDocument"
code no longer applies to the document.

---
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)

If CloseMode = 0 Then
Me.Hide
Selection.HomeKey Unit:=wdStory, Extend:=wdMove
ActiveWindow.View.Type = wdPrintView
Application.ScreenUpdating = True
End If

End

End Sub
---
Private Sub cmdCancel_Click()

Me.Hide
Selection.HomeKey Unit:=wdStory, Extend:=wdMove
ActiveWindow.View.Type = wdPrintView
Application.ScreenUpdating = True

End

End Sub
---

Any ideas why this could be happening? We think it may be that the End
statement just stops everything and negates the ThisDocument code. Is there
an available alternative that will keep the ThisDocument code intact?

Any help is appreciated! Thanks!
 

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