From: Word_2007_SASS on
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!
From: Fumei2 via OfficeKB.com on
why are you even using End?


Word_2007_SASS wrote:
>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!

--
Gerry

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201004/1

From: Karl E. Peterson on
Fumei2 via OfficeKB.com wrote:
> why are you even using End?

+1

The Evil End Statement
http://obob.com/cis58/evilend.html

--
..NET: It's About Trust!
http://vfred.mvps.org