Remove character style with direct formatting

M

m rafala

I have text styled with a custom character style. Some of that text also has
direct formatting applied (bold, ital, etc.).

I need to remove the character style, but retain the direct formatting.

Possibly I also need to retain any font formatting provided by the style as.

I can do this:

For Each c In Selection.Characters
Set f = c.Font.Duplicate
c.Font.Reset
c.Font = f
Next c

but this is slow and I keep thinking I'm missing a simpler, faster way to do
this. Any suggestions?
 
H

Helmut Weber

Hi,

like this:

Sub Test7()
Dim aStl As Style
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
For Each aStl In ActiveDocument.Styles
If aStl.Type = 2 Then
With ActiveDocument.Range.Find
.Style = aStl
While .Execute
rDcm.Font.Reset
Wend
End With
End If
Next

End Sub

Search for character-styles only,
that is style.type = 2,
while found
reset

There are other ways as well.


--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
M

m rafala

Unfortuneately, all this does is reset the font formatting of the styled
text. I need to retain any direct formatting.
 
H

Helmut Weber

Hi Rafala,

i hadn't quite got what you wanted to do.

Maybe, if you don't need the particular character style any longer,
deleting it from the doc would help you.

Sub Test7()
Dim aStl As Style
Dim rDcm As Range
Set rDcm = ActiveDocument.Range
For Each aStl In ActiveDocument.Styles
If aStl.Type = wdStyleTypeCharacter And _
aStl <> "Default Paragraph Font" Then
With rDcm.Find
.Style = aStl
While .Execute
rDcm.Select ' for testing
Stop ' for testing
ActiveDocument.Styles(aStl).Delete
Wend
End With
End If
Next
End Sub

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
M

m rafala

Ah. Excellent. I didn't think of that.

This does indeed retain the direct formatting. I do loose the formatting
that's build into the style (such as bold), but I can reapply that if needed
after deleting the style. thanks.
 

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