Determining if a range is within a merge field

H

hafabee

I have a routine that loops through all the words in a doc (For Each
objWord In objPara.Range.Words) looking for certain words.

I want to ignore merge field names. Right now, the routine is picking
up each "word" of the merge field name. For example, if the merge name
is "«First_Name»" my routine is picking up the words "«" "First"
"_" "Name" and "»".

Is there any way to tell if a given range (such as "First" in the
above example) is within a merge field? Or, even better, is there any
way to somehow hide all merge fields at the start of my routine?

Thanks in advance for any advice you may have.
 
T

That Guy

I am guessing that you are using MS word 2007.

I do not have experience with 2007 but from a programmers point of
view I would do the following:

If you are coding something to happen with each word, as I am guessing
you are, in your for loop you should add limiting criteria. I imagine
that you will not see the 'words' "«" and "»" anywhere else in your
document other than wrapping around a merge field name.

If this is the case then you simply need to tell your loop to ignore
any words between the "«" and "»". Do this when you are checking the
words. For added value to your code find the longest merge name and
count the amount of 'words' it contains. tell your loop to ignore a
max of that many words and if it does not find a closing "»" by the
time it reaches the name limit, then stop ignoring the words and
assume that the document contains the word "«".

if you post your loop body I may be able to help.

Feel free to email me directly.
 

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