Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace only in text box within header 2

Status
Not open for further replies.

sophisticatedpenguin

Technical User
Oct 12, 2005
31
GB
Hi,

I'm trying to do a search and replace only in the headers of a (very long) Word document. The text is in text boxes within the headers.

I found this site and it looks as though the final piece of code should be useful with modification. The problem is that I can't work out how to change it so that it only looks in headers rather than looking in all the other StoryTypes.


Can anyone help?

Many thanks in advance,
SP
 
1. It is unfortunate that you have your text in textboxes. It would be much MUCH easier if it was just text. Mind you, that expresses my personal hatred of textboxes.

2. To just action the header stories, limit your Select Case to the values of those stories.

7 (PrimaryHeaderStory)
8 (EvenPageHeaderStory)
10 (FirstPageHeaderStory)

So instead of:
Code:
Select Case rngStory.StoryType
   Case 6 , 7 , 8 , 9 , 10 , 11
use:
Code:
Select Case rngStory.StoryType
   Case 7, 8, 10

Now only the header stories (7,8, 10) will be actioned. It is a good standard practice to keep the Case Else ( ' do nothing).

As a possible helpful tip, try exploring the Object Browser in the VBE. If you type StoryType into the search box, you get a list of everything that uses "StoryType". Then click "wdStoryType", and it lists all the Enum members of StoryType. If you click any one of them (say, wdPrimaryHeaderStory) it displays its Constant value.

Const wdPrimaryHeaderStory = 7

Thus you can find out the StoryType values (7, 8, 10) that are applicable to just headers.

Gerry
 
Thanks ever so much Gerry! The text is in text boxes because some of the pages are landscape but the headers and footers still have to appear along the short edges. On those pages there is a text box that is 'in' the header but actually positioned down the right-hand side.

Thanks for the tip about the Object Browser. I will try to use this to figure out more for myself.

Your help is very much appreciated.
Kind regards,
Katie
 
Hi again,

I changed the Select Case option but the macro is still replacing text in the main document as well as in the headers. Any thoughts on what else I might need to change?

Many thanks,
Katie
 
The original code replaces text twice, once in plain text (after 'Do', all stories, no condition) and second time in shapes shapes only, inside 'Select Case'. Just delete the first action.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top