F
Fletcher James
I need to determine whether character styles are in use for any sub-portion
of a Range.
If you've worked with Range properties, you know that MOST properties (e.g.
..Bold) return a special undefined value (such as 9999999) when the property
value is not uniform over the range. However, Word uses the Range.Style
property for BOTH Paragraph Styles and Character Styles. If you query the
..Style property for a Range which is ENTIRELY in one Character Style, the
value will be the name of the Character Style. The moment that the Range
overlaps by a single character, into a run with either another Character
Style or no Character Style, then the return value will be the name of the
Paragraph Style for the Range. (If the Range overlaps two paragraphs with
different Styles, then Range.Style will be Nothing)
One solution is to check every single character in the range. That's
effective, but extremely slow. Word-by-word checks would be faster, but not
100% reliable.
A second solution is to examine all of the character styles in defined for
the document (I'm really only interested in the ones which Word has created
on its own from Paragraph styles, such as "Heading 1 Char"), map out
everywhere they are in use in the document (including Footnotes, etc.), and
then see whether any of those ranges overlap the areas of the document that
are of interest to me. That is faster than solution 1, but requires 1-200
lines of VBA code, and is still a kludge.
Does anyone have a direct and elegant way of accomplishing this?
A direct cc: to me, in addition to a reply-to-group, would be appreciated.
--
Fletcher James
President
Levit & James, Inc.
(703)771-1549
MailTo:[email protected]
http://www.levitjames.com
of a Range.
If you've worked with Range properties, you know that MOST properties (e.g.
..Bold) return a special undefined value (such as 9999999) when the property
value is not uniform over the range. However, Word uses the Range.Style
property for BOTH Paragraph Styles and Character Styles. If you query the
..Style property for a Range which is ENTIRELY in one Character Style, the
value will be the name of the Character Style. The moment that the Range
overlaps by a single character, into a run with either another Character
Style or no Character Style, then the return value will be the name of the
Paragraph Style for the Range. (If the Range overlaps two paragraphs with
different Styles, then Range.Style will be Nothing)
One solution is to check every single character in the range. That's
effective, but extremely slow. Word-by-word checks would be faster, but not
100% reliable.
A second solution is to examine all of the character styles in defined for
the document (I'm really only interested in the ones which Word has created
on its own from Paragraph styles, such as "Heading 1 Char"), map out
everywhere they are in use in the document (including Footnotes, etc.), and
then see whether any of those ranges overlap the areas of the document that
are of interest to me. That is faster than solution 1, but requires 1-200
lines of VBA code, and is still a kludge.
Does anyone have a direct and elegant way of accomplishing this?
A direct cc: to me, in addition to a reply-to-group, would be appreciated.
--
Fletcher James
President
Levit & James, Inc.
(703)771-1549
MailTo:[email protected]
http://www.levitjames.com