Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

Remove character style with direct formatting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
m rafala - 12 Sep 2007 18:11 GMT
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?
Helmut Weber - 12 Sep 2007 21:38 GMT
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.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

m rafala - 13 Sep 2007 13:22 GMT
Unfortuneately, all this does is reset the font formatting of the styled
text. I need to retain any direct formatting.

> Hi,
>
[quoted text clipped - 23 lines]
>
> There are other ways as well.
Helmut Weber - 13 Sep 2007 15:23 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

m rafala - 13 Sep 2007 16:22 GMT
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.

> Hi Rafala,
>
[quoted text clipped - 21 lines]
> Next
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.