Reset font/character formatting while preserving character style text

A

andreas

Dear experts:

this maybe a tough one. I need to have a macro for ...
....resetting font formatting while preserving character-styled text.

If I clear out all direct font formatting by using Ctrl+A, Ctrl
+Spacebar the direct formatting is reset BUT it also deletes/resets my
(user-defined) character-styled formatting.

Any idea how this could be solved. Help is much appreciated. Thank you
very much in advance.

Regards, Andreas

P.S. I found a macro which does the above. It works fine in small
documents but it regrettably does not work on large documents. It
falls into an endless loop on the latter ones.
 
G

Graham Mayor

Hmmmm. I don't immediately see any other way but to check the formatting of
each word (or character) in turn and if there is manual formatting (i.e. the
style applied is the underlying style and not a character style) to reset
it. With a long document this can take a long time to process if you check
by word, and a seriously long time to process if you check each character
e.g.

Dim pStyle As String
Dim rPara As Range
With ActiveDocument
For i = 1 To .Paragraphs.Count
pStyle = .Paragraphs(i).Style
Set rPara = .Paragraphs(i).Range
With rPara
For j = 1 To .Words.Count
If .Words(j).Style = pStyle Then
.Words(j).Font.Reset
End If
Next j
End With
Next i
End With


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

andreas

Hmmmm. I don't immediately see any other way but to check the formatting of
each word (or character) in turn and if there is manual formatting (i.e. the
style applied is the underlying style and not a character style) to reset
it. With a long document this can take a long time to process if you check
by word, and a seriously long time to process if you check each character
e.g.

Dim pStyle As String
Dim rPara As Range
With ActiveDocument
    For i = 1 To .Paragraphs.Count
        pStyle = .Paragraphs(i).Style
        Set rPara = .Paragraphs(i).Range
        With rPara
            For j = 1 To .Words.Count
                If .Words(j).Style = pStyle Then
                    .Words(j).Font.Reset
                End If
            Next j
        End With
    Next i
End With

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>









- Show quoted text -

Graham:

great job. It is working as desired. I have tried it on small
documents. It is fairly quick. I am gonna give it a try on a long
document. As you said it may take "ages" but it is worth waiting if
the job is done well. Thank you very much for your professional help.
Regards, Andreas
 
A

andreas

Hmmmm. I don't immediately see any other way but to check the formatting of
each word (or character) in turn and if there is manual formatting (i.e. the
style applied is the underlying style and not a character style) to reset
it. With a long document this can take a long time to process if you check
by word, and a seriously long time to process if you check each character
e.g.

Dim pStyle As String
Dim rPara As Range
With ActiveDocument
    For i = 1 To .Paragraphs.Count
        pStyle = .Paragraphs(i).Style
        Set rPara = .Paragraphs(i).Range
        With rPara
            For j = 1 To .Words.Count
                If .Words(j).Style = pStyle Then
                    .Words(j).Font.Reset
                End If
            Next j
        End With
    Next i
End With

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>









- Show quoted text -

Hey Graham:

just tried your macro on a 150 page document. It took about 15
minutes to run. It is running fast in my view, considering what this
macro has to work.
Regards, Andreas
 
G

Graham Mayor

Change .Words to .Characters - that should slow it down a bit ;)
That would be necessary if parts of words were formatted.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

andreas

Change .Words to .Characters - that should slow it down a bit ;)
That would be necessary if parts of words were formatted.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>






- Show quoted text -

Graham,

ok, thank you again for your terrific help. Regards, Andreas
 
G

Graham Mayor

andreas said:
Graham,

ok, thank you again for your terrific help. Regards, Andreas

You are welcome :)

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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