Searching Within Header/Footer

B

Bright Spark

Looking for help again, I'm afraid - this time with regard to the
Search feature. We prepare documents that have double asterisks in
them (**) where we are to insert information, and consequently when we
complete a document we need to run a search through to make sure we
haven't left any stars in there. It's easy enough to just search for
the double stars, but it doesn't ever check the header or footer when
the search runs. I haven't been able to find a command to make the
search include the headers and footers - hopefully someone can steer
me in the right direction.

Using Word 2003.

Thanks again in advance.

Bright Spark
 
G

Graham Mayor

You can search for two asterisks anywhere in the document with a macro. The
following will look in the various header footer ranges and delete any
instances of two asterisks. It will also eliminate them from the main text
area. If you have them in other parts of the document not covered by the
macro e.g. text boxes, then the macro would need to be extended to cover
them, but let's cross that bridge if we come to it..

Sub ClearAsterisks()
Dim oSection As Section
Dim oRng As Range
Dim oHeader As HeaderFooter
Dim oFooter As HeaderFooter
Dim sFindText As String
sFindText = "**"

For Each oSection In ActiveDocument.Sections
Set oRng = oSection.Range
With oRng.Find
.Text = sFindText
Do While .Execute(Forward:=True) = True
oRng.Delete
Loop
End With
For Each oHeader In oSection.Headers
If oHeader.Exists Then
Set oRng = oHeader.Range
With oRng.Find
.Text = sFindText
Do While .Execute(Forward:=True) = True
oRng.Delete
Loop
End With
End If
Next oHeader
For Each oFooter In oSection.Footers
If oFooter.Exists Then
Set oRng = oFooter.Range
With oRng.Find
.Text = sFindText
Do While .Execute(Forward:=True) = True
oRng.Delete
Loop
End With
End If
Next oFooter
Next oSection
End Sub

http://www.gmayor.com/installing_macro.htm


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
B

Bright Spark

Graham, thank you very much for your response. Unfortunately, you
have completely lost me with the macro stuff you wrote in. I have no
idea what to do with that - it looks like programming language - :eek:))
I do have a short easy "regular" macro that I use which simply
searches for the stars and takes me to them (I just need to be able to
get to them on a search, not delete them), but the search doesn't
include the headers or footers at all. Is there just no way to run a
search which will include searching inside the headers without writing
a complicated macro perhaps?

Thanks.

Bright Spark
 
S

Suzanne S. Barnhill

Graham, thank you very much for your response. Unfortunately, you
have completely lost me with the macro stuff you wrote in. I have no
idea what to do with that - it looks like programming language - :eek:))

See http://www.gmayor.com/installing_macro.htm (and note that Graham
included that link at the end of the macro). A macro *is* programming
language, and if you have a macro but have never seen VBA, then presumably
you recorded the macro, but if you looked at it, it would look like that.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
B

Bright Spark

Hi, Suzanne - yes, that's correct. I recorded a macro but have not
seen/used VBA.

Is there just no way to search inside headers/footers without a macro,
then?

Thanks.

Bright Spark
 
S

Suzanne S. Barnhill

Generally speaking, when using Replace, if you click Replace All, Word will
search all layers, but it searches the entire document body before it
searches the other layers. With Find, if you use Find All, the dropdown for
"Highlight all items found in" will give you a choice of all the layers that
contain text (including "Headers and Footers"), but you have to search them
one by one.

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
http://word.mvps.org
 
B

Bright Spark

Thanks, Suzanne. I see what you are saying and see that for a simple
"find" it just doesn't work with Word unless you run two separate
searches, one for the Main Document and one for the Headers and
Footers. Replace doesn't work for us since we have to add something
different for each set of asterisks, so that's not a reasonable
option. We just needed to be able to have the headers/footers
included in the "Find" search for **.

Thank you both for your help.

Bright Spark
 

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