Word VBA >> replace header text: get section data in header to halt infinite loop VBA

by shane » Sun, 18 Jul 2004 23:44:56 GMT

VBA macro, which replaces header text when recorded, does
NOT replace header text when called.

I then forced macro into header and it replaces fine, but
the ActiveWindow.ActivePane.View.NextHeaderFooter goes into
an infinite loop.

Tried getting section number using old WordBasic command
(SelInfo(2)), as well as page number (SelInfo(3))
NewPg = WordBasic.SelInfo(3)
then compairing "NewPg" with prior page variable "OldPg".

Variables don't seem to fill.

Any suggestions appreciated. THANK YOU.




Word VBA >> replace header text: get section data in header to halt infinite loop VBA

by Jay Freedman » Mon, 19 Jul 2004 00:53:06 GMT


Similar Threads

1. keep section header (higher section) together with lower section footer

I have an inventory report that shows item Category, Sub-Category, and
the Item.

Grouped by each.

I show the Category header (just a title) with the Sub-Category footer
(all summary info). This gives me everything I need to see and things
look great.....except for when the Header doesn't stay with the
Footer.

I've tried putting the Header title with the Footer section, but it
duplicates even when I check the box in format section box.

Is there a way to keep these two together? I've tried the previous or
next and that doesn't work. I'm stumped.

2. replace text in all header stories of a document with several sections - Word VBA

3. Infinite Loop with a find and replace

Hi, I'm wondering if someone would be kind enough to help me.  I'm working 
with a script and want to highlight different character names and their 
dialogue.  I can highlight the character names easily with Find and Replace.  
But their subsequent dialogue, in a new paragraph under their character 
names, is proving more difficult.  I've created a macro that will do this, 
but when it reaches the end of the script, it asks me if I want to continue 
searching at the top of the document.  If I say yes, it loops infinitely; if 
I say no, it keeps asking again and again, another loop.  Here's my code, 
below.  Any help is appreciated.  Thanks.


Sub HighlightEllie()
'
' HighlightEllie Macro
'
'
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Highlight = True
    Options.DefaultHighlightColorIndex = wdYellow
    
    With Selection.Find
        .Text = "ELLIE^p"
        .Replacement.Text = "ELLIE^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = True
    End With
     
     
    Selection.Find.Execute Replace:=wdReplaceAll
    Selection.Find.ClearFormatting
    
    With Selection.Find
        .Text = "ELLIE^p"
        .Replacement.Text = "ELLIE^p"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = True
     End With
    
   
    Selection.HomeKey Unit:=wdStory
    Selection.Find.ClearFormatting
     
    Do While True
    
    With Selection.Find
        .Text = "ELLIE^p"
        .Forward = True
        .Wrap = wdFindAsk
        .MatchCase = True
    End With
    
    
    Selection.Find.Execute
    
     
    Selection.MoveDown Unit:=wdLine, Count:=1
    Selection.HomeKey Unit:=wdLine
    Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
    Options.DefaultHighlightColorIndex = wdYellow
    Selection.Range.HighlightColorIndex = wdYellow
    Selection.HomeKey Unit:=wdLine
    
    Loop
       

End Sub

4. VBA to replace text in document body & header - Word VBA

5. For the selected section and the following one: unlink headers from previous section

Dear Experts:

Below macro unlinks the current headers from the previous section. How
has this code to be expanded if I also wanted the following section's
headers to be unlinked from the previous section?

Help is much appreciated. Thank you very much in advance. Regards,
Andreas

With Selection.Sections(1)
.Headers(wdHeaderFooterPrimary).LinkToPrevious = False
.Headers(wdHeaderFooterFirstPage).LinkToPrevious = False
.Headers(wdHeaderFooterEvenPages).LinkToPrevious = False
End With

6. Find and replace text in header of binary file - Visual Basic/VB

7. Macro To Replace Text In Header

Hi not sure why my macro doesnt replace stuff in the 
header

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "<Subject>"
        .Replacement.Text = NameTextBox.Text
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll


PLZ HELP

8. Find/Replace Text in Headers - Word VBA