Code clarification for locking header/footer

S

sandy

I found Bill Coan's article regarding locking
header/footer programatically, my proble is that I don't
know what to "customize" and what to keep as code.

If someone can tell me what I am supposed to "customize"
in the code below, I would greatly appreciate it.

Thanks so much,
BTW - Happy Mother's Day
sandy

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
 
P

Peter Hewett

Hi sandy

Have you actually tried it? You don't need to do anything to do anything with it. It
will automatically prevent you from editing the documents Header or Footer. All it does
is detect the StoryType being edited and if it's a Header or Footer it just dumps you back
at the documents MainStory (the body text).

Create a template, add the code, save the template. Create a new document based on your
template and then try editing the documents Header/Footer.

HTH + Cheers - Peter
 
S

sandy

Yes, I have gone to Tools/Macro/Visual Basic Editor -
pasted the code. Saved the template and opened it as a New
Document and I can get into the header with no problem.

Do I need to protect it or something?

thanks,
sandy
-----Original Message-----
Hi sandy

Have you actually tried it? You don't need to do
anything to do anything with it. It
will automatically prevent you from editing the documents Header or Footer. All it does
is detect the StoryType being edited and if it's a Header
or Footer it just dumps you back
at the documents MainStory (the body text).

Create a template, add the code, save the template.
Create a new document based on your
 
P

Peter Hewett

Hi sandy

1. What version of Word are you using?
2. Did you paste the code into the ThisDocument module?

Cheers - Peter


Yes, I have gone to Tools/Macro/Visual Basic Editor -
pasted the code. Saved the template and opened it as a New
Document and I can get into the header with no problem.

Do I need to protect it or something?

thanks,
sandy
anything to do anything with it. It
or Footer it just dumps you back
Create a new document based on your

HTH + Cheers - Peter
 
J

Jay Freedman

Hi Sandy

Just to make sure: Did you paste the code into the ThisDocument module
of the template? It won't work in any other module.

If that's ok, look at the code in the editor. Is anything there
colored red? If you just copied the code from the web page and pasted
it into the editor, the lines between the subroutines may be red.
Those are syntax errors, which can keep the code from running. Delete
them and save the template again, then create a new document based on
it.

You don't have to protect the document or the template.
 

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