finding direct formatting

J

jimi_hendricks

Hi,

I have a function which loops through all styles in the styles collection,
but now i want to extend it to capture all direct formatting as well. Is
there a neat (efficient) way of capturing all variations of direct formatting?

For info (if it helps!): i am developing a feature to allow users to flip
between the usual styled and formatted view of their document, and one which
essentially renders it as plain text. It is crucial that they be able to edit
text while in this plain mode, and they must be able to revert to the fully
formatted and styled mode when done.

For proper styles, i copy each style in use (e.g. Heading 3), give the copy
an obscure prefix (e.g. obscureprefix_Heading 3), base all such styles on
Normal, then use find replace to find all text which uses the original style,
and tell it instead to use the copied style. That way when i revert to the
usual mode, i just search for all text using a style beginning
'obscureprefix_' and replace it with the original style which then
reintroduces all the appropriate style properties. lovely.

Now i want to do a similar thing for direct formatting. So, i can't just
remove all direct formatting (which is tempting!), but i suspect i will have
to find each case of direct formatting, create a temporary style, e.g.
'temp_obscureprefix_bold, italic' (to save the properties in) then begin a
process similar to the above.

When reverting to the usual mode, i will need to do a bit more work to apply
direct formatting (as per the properties stored in the temp style) before
removing the style itself, to ensure the the document does truly revert to
the way it was before.

As you can see, the process is likely to become processor intensive unless
cases of direct formatting can be neatly captured and traversed in a loop.
Since direct formatting appears in the 'styles and formatting' pane as though
it were a style (but without actually being a style), Word itself must have
some way of identifying direct formatting easily, no?

Any help or pointers would be greatly appreciated.

Thanks for your time.
 
H

Helmut Weber

Hi,
Word itself must have some way of
identifying direct formatting easily, no?

Easily? I don't know.
Direct formatting is listed in the formatting pane?
I don't know either.
Bold is listed in the formatting pane
as "Style + bold", whereas subscript is not.

If you can restrict direct formatting to some kinds
like bold, italic, underline then
it's still a lot af tedious coding, but possible.

For reasons of speed, I think, you have to loop
over entitites as document, paragraph, word, character.

Like this, to find the first word in a doc
with a formatting of bold or not bold that is different from
the formatting of the paragraphs style concerning bold.
' ----
Sub findbolddirect()
Dim rDcm As Range
Dim rPrg As Paragraph
Dim rWrd As Range
' Dim rChr As Range

If ActiveDocument.Range.Font.Bold = 9999999 Then
'direct formatting bold (yes, no) found
For Each rPrg In ActiveDocument.Paragraphs
If rPrg.Range.Font.Bold = 9999999 Then
' direct formatting bold (yes, no) in paragraph"
For Each rWrd In rPrg.Range.Words
If rWrd.Font.Bold <> rPrg.Style.Font.Bold Then
rWrd.Select
Stop
' same Loop for characters
' and what you gonna do if found?
End If
Next
End If
Next
End If
End Sub

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 

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