How do I apply this macro?

jmt356
SilverLounger
Posts: 2389
Joined: 28 Mar 2010, 01:49

How do I apply this macro?

Post by jmt356 »

I found this handy macro for deleting all of the headers and footers in a document:

Sub RemoveHeadAndFoot()
Dim oSec As Section
Dim oHead As HeaderFooter
Dim oFoot As HeaderFooter

For Each oSec In ActiveDocument.Sections
For Each oHead In oSec.Headers
If oHead.Exists Then oHead.Range.Delete
Next oHead

For Each oFoot In oSec.Footers
If oFoot.Exists Then oFoot.Range.Delete
Next oFoot
Next oSec
End Sub


Some time ago, I was advised on Woody's lounge (predecessor to Windows Secrets Lounge) that to apply a macro to a document, I should:
a. In Word, press Alt+F11 to activate the Visual Basic Editor.
b. Click in Normal in the Project Explorer (the treeview on the left)
c. Select Insert | Module.
d. Type or paste the code into the window that appears.

If I follow those steps, then will the command RemoveHeadAndFoot be available only in documents based on the Normal template?

Also, before I save this macro, it will only delete headers and footers in documents if I run it, correct (I want to make sure that upon saving it, I will not find all of the headers and footers of all of my Normal.dot documents deleted)?
Regards,

JMT

User avatar
StuartR
Administrator
Posts: 12605
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: How do I apply this macro?

Post by StuartR »

Normal.dotm (or normal.dot for older versions of Word) is a global template. Any macros in this template are available regardless of the template you have attached to the active document.

This macro will only run if you run it manually, or call it from another macro.
StuartR