PegDalyPA was telling us:
PegDalyPA nous racontait que :
> HELP!
>
[quoted text clipped - 24 lines]
> 'Go into Header (I think it can't find shapes in headers unless
> cursor is in a header)
Avoid the Selection Object like the pest, especially when dealing with
headers/footers. It is very unreliable and slows down the execution.
In other words, there is no need to have code actually place the cursor in a
header or footer.
> ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
>
[quoted text clipped - 7 lines]
>
> Thanks for any help you can provide. I'm losing my mind over this!
It is always better to start a new thread than to latch on an existing one
with a different question, even if it is sort of related.
Meanwhile, for more detailed information on dealing with storyranges and
searching them in documents, see:
http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm
I have adapted that code for your purpose:
'_______________________________________
Option Explicit
'_______________________________________
Public Sub FindReplaceHeaderFooter()
Dim rngStory As Word.Range
Dim pFindTxt As String
Dim lngJunk As Long
pFindTxt = "PowerPlusWaterMarkDraft"
'Fix the skipped blank Header/Footer problem
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType
'Iterate through all story types in the current document
For Each rngStory In ActiveDocument.StoryRanges
'Iterate through all linked stories
Do
Select Case rngStory.StoryType
'All headers, footers...
Case 6, 7, 8, 9, 10, 11
SearchInStory rngStory, pFindTxt
Case Else
'Do Nothing
End Select
On Error GoTo 0
'Get next linked story (if any)
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next
End Sub
'_______________________________________
'_______________________________________
Public Sub SearchInStory(ByVal rngStory As Word.Range, _
ByVal strSearch As String)
Dim shpToDelete As Shape
If rngStory.ShapeRange.Count > 0 Then
For Each shpToDelete In rngStory.ShapeRange
If InStr(1, shpToDelete.Name, strSearch) > 0 Then
shpToDelete.Delete
End If
Next
End If
End Sub
'_______________________________________

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
PegDalyPA - 06 Sep 2006 14:37 GMT
Jean-Guy, you are my ANGEL!
It works beautifully! I don't even know what all of the code is doing (I can
understand most of it, but was never trained for this), but I've tried
running it on several sample documents and it worked on every one! Merci!
Merci! Merci! Now I just need to finish writing the code that actually
inserts those shapes into ALL sections, instead of just the first two headers
in a document, which is as far as I had gotten with that other code.
Thanks again for your help,
Peg