Hi Bala
Technically, this question belongs in the office.developer.automation newsgroup, or even better, in a Word-oriented programming group, such as word.vba.general (see the "Please Read First" posting at the top of this forum). There, you'd get the some of the best minds for the Word object model thinking about possible approaches. Here's my take on it:
The problem is that, as I understand it, your code runs once? What you want, I should think, is something more dynamic. I' m wondering if it wouldn't be better to nest the StyleRef in an IF field (or use a set of nested IF fields). Check whether the result is an empty string; if so, try the next level, and so on, until you get the result you need. Very roughly:
{ IF "{ StyleRef 1 }" = "" "{ Style Ref 2 }" "{ StyleRef 1}" }
Building a set of nested fields programmatically isn't terribly straight-forward, however. There is an article at word.mvps.org (http://word.mvps.org/faqs/macrosvba/NestedFieldsWithVBA.htm), but I don't agree with the approaches it presents. Nested field CAN be created using the Range object, it just takes a little more work. One approach is described here http://gregmaxey.mvps.org/Field_Macros.htm (end of the page).
-- Cindy Meister (Word MVP) |