Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

Please can someone help. I have a client using a VB6 built app. At various stages this runs through a Word Document Template and replaces various fields with info from a Database (this is just background info).

They have recently made changes to the header, so now the header contains information that needs to be replaced.

I have searched CodeProject, as well as quite extensively on the net and can't find a valid solution...

The best I can come up with is the below code (which doesn't crash, but it doesn't find the text, even though it IS in the file)...

VB
ActiveDocument.StoryRanges(wdPrimaryHeaderStory).Select

Do While ActiveDocument.StoryRanges(wdPrimaryHeaderStory).Find.Execute("<User_Branch_Tel>") = True

ActiveDocument.StoryRanges(wdPrimaryHeaderStory).Cut
ActiveDocument.StoryRanges(wdPrimaryHeaderStory).InsertAfter "Test"
Loop
Posted

1 solution

Hi everyone,

After lots of persistence I found the answer:

VB
Set Range = NewApp.ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range
    Do While Range.Find.Execute("TextToSearchFor") = True
        Range.Cut
        Range.InsertAfter "TextToReplace"
    Loop


Thanks...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900