Results 1 to 15 of 15
  1. #1
    Lounger
    Join Date
    May 2002
    Location
    Cleveland, Ohio, USA
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Find Character Styles (Word 2000 SR-1)

    Howdy
    I am trying to find certain character styles and format the text to resemble the current paragraph style. This may sound goofy, but what I trying to do is replace DeltaView character styles in a redline with the current paragraph style. Any sugesstions?
    Smiles
    Kay <img src=/S/confused.gif border=0 alt=confused width=15 height=20>
    <img src=/S/doctor.gif border=0 alt=doctor width=25 height=33>

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Find Character Styles (Word 2000 SR-1)

    In the edit / replace box you can search for "Any Character" with the formatting you want to change and replace it with "Find What Text" formatted as Default Paragraph font.

    StuartR

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find Character Styles (Word 2000 SR-1)

    Hi Kay:
    I don't know if you have other direct formatting in the document that don't want to remove. If you don't, just press select everything & press Ctrl+Spacebar. This will remove all direct formatting & character styles.

  4. #4
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: Find Character Styles (Word 2000 SR-1)

    I actually the same assistance. Using Ctrl+Spacebar won't work because there is other formatting in documents. What I'm trying to do, and what I assume Kay is trying to do, is to search for two at least two Styles: DeltaView Deletions and DeltaView Insertions (I think that's what it's called). I can do this using the Find or Replace dialog. And it's easy for the Insertions, you just use the Replace dialog to search for every character with the style and flip it to the default paragraph style (this will remove DeltaView's Insertion formatting). It gets more complicated with the Deletions style. We don't want that converted to the default style -- we want the text removed! I can't seem to do this with Replace because it won't replace a character with a deletion. I guess we need a looping macro that will find every iteration of a character with the DeltaView Deletions style applied and then delete that character. Any suggestions on this??

    Thx.

    -Rich Belthoff

  5. #5
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find Character Styles (Word 2000 SR-1)

    Unless I'm missing something: Just leave "Replace with:" empty.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  6. #6
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: Find Character Styles (Word 2000 SR-1)

    OK, duh, that works! <grin> I guess I confused myself because at first I was trying to search and replace just the DeltaView style and replace it with the default character style so I had the "any character" codes in the Replace box.

    Thx.

    -Rich Belthoff

  7. #7
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: Find Character Styles (Word 2000 SR-1)

    Klaus,

    Can I pick up where this left off? We were having a discussion about searching and replacing character styles. What we discussed works, but it tends to destroy any direct formatting. At this point, I have a macro that searches for characters with a specific style applied and then applies the Default Paragraph Font style. The problem is that if the characters have direct formatting applied, e.g., a different font, bold, or italics, this gets removed when the Default Paragraph Font style is applied. Is there a way to search for a Character Style in a document and then just remove it without affecting any direct formatting that may have been applied to the area affect by the Character Style? If I still used WordPerfect, I could just delete the <Style On> code, but this obviously doesn't work in Word (and this is Word 2000 and above I'm using on different computers). Any thoughts or suggestions??

    Thx.

    -Rich Belthoff

  8. #8
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find Character Styles (Word 2000 SR-1)

    Hi Rich,

    This is an interesting problem. Let me make sure I understand you correctly: you want to find any text formatted with a particular character style, and then remove that character style (and its associated formatting), but retain any other direct formatting applied to the text?

    After some experimentation, it looks like that's a lot tricker than it sounds. For example, I can't think of any way to do that from within the Word GUI -- please correct me if I'm mistaken.

    I can think of three possible approaches:

    (1). You can find text that uses that character style, and remove the character style, but still retain all of the font-level formatting on the text (including that defined as part of the character style). This is the easiest approach:
    <pre>Sub RemoveCharStyleRetainFormatting()
    Dim char as Range
    Dim f As Font
    For Each char In ActiveDocument.Characters
    If char.Style = char.Parent.Styles("Style To Remove") Then
    Set f = char.Font.Duplicate
    char.Font.Reset
    char.Font = f
    End If
    Next char
    </pre>


    (2). If the character style you want to remove has just one or two components (say Bold and Underlined), and you want the style, along with those formats removed, you can modify it slighty:
    <pre>Sub RemoveCharStyleRetainFormatting()
    Dim char as Range
    Dim f As Font
    For Each char In ActiveDocument.Characters
    If char.Style = char.Parent.Styles("Style To Remove") Then
    Set f = char.Font.Duplicate
    char.Font.Reset
    char.Font = f
    char.Font.Bold = False
    char.Font.Underline = wdUnderlineNone
    End If
    Next char
    </pre>


    (3). If you wanted something more general purpose that would work for any character style, you'd have to get more complex, first capturing all possible font information from the text in question, then discarding that which is part of the character style. It's possible, but would likely be much lengthier than these first two scenarios, one of which I hope works for your situation.

    Cheers!

  9. #9
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: Find Character Styles (Word 2000 SR-1)

    Thanks. I'll try your code. I think you understand correctly. I want to find text with a specific char style and then remove the style without removing direct formatting. I figured it would be really difficult! In any event, I tried this: using a macro to delete the styles that I want to remove. I figured this was a shortcut to searching and reformatting individual characters. This works somewhat, but at times it removes some of the direct formatting, but not all (e.g., something might be bold and underlined, and deleting the style also winds up deleting the underlining). I haven't had a chance yet to see if this occurs throughout the doc or just in certain situations.

    Thx.

    -Rich Belthoff

  10. #10
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: Find Character Styles (Word 2000 SR-1)

    I haven't had a chance to try out the code yet due to work issues, but I'll try it this weekend in the broader scheme of my macro and let you know how it works out. Thanks for all the help.

    Thx.

    -Rich Belthoff

  11. #11
    3 Star Lounger
    Join Date
    Apr 2004
    Location
    Boston, Massachusetts, USA
    Posts
    389
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find Character Styles (Word 2000 SR-1)

    Hi St3333ve,

    You got me thinking about the deleting the styles approach. The way I see it, there are two problems: First, what if you still want the style available in the document, and second, what if it's a built in style, which theoretically can't be deleted? After a bit of experimentation, I came up with the following, which I think adequately addresses both points. First, the formats associated with the file are preserverd, then the style is deleted (interestingly enough, no error is raised when you try to delete a built-in character style), then the style is recreated, and then the original formats are restored to the style.

    Feedback is always welcome.

    <pre>Function RemoveCharacterStyleRetainDirectFormatting( _
    ByVal sStyleName As String, _
    doc As Document)

    Dim f As Font
    Dim styChar As Style
    Dim bIsBuiltIn As Boolean

    Set styChar = doc.Styles(sStyleName)
    bIsBuiltIn = styChar.BuiltIn
    Set f = styChar.Font.Duplicate

    styChar.Delete
    If Not bIsBuiltIn Then
    doc.Styles.Add Name:=sStyleName, _
    Type:=wdStyleTypeCharacter
    End If
    doc.Styles(sStyleName).Font = f

    End Function
    </pre>


  12. #12
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: Find Character Styles (Word 2000 SR-1)

    I will try out your code. I suggested deleting the style because what I'm doing is creating a "clean" version of a redline created using WorkShare's DeltaView program. It uses character styles to show it redline formatting options. It's easy to handle "deletion" type styles (e.g., a style flagging text that has been deleted in the redline) because I just search for the style and replace with nothing. For added text, it gets more difficult. At first, I was searching for the style and replacing with Default Paragraph Font. The problem with this is that the added text might be a different font, or have different font attributes applied. So, I thought that deleting the style might work. In this case, they will never be built-in styles, nor will I care if they are still in the file. However, the problem with this is that like using the Default Paragraph Font method it sometimes removes direct formatting. So, I tried the code in a message or two back to strip the Char Style formatting and it seems to work. However, it is somewhat slow, especially on a large file (and in a redline, there could be a LOT of characters with Char Styles applied). This is not a function of the code, just a function of the amount of characters to change. Although it doesn't both me if the Char Style is deleted, I might try your code anyway.

    Thx.

    -Rich Belthoff

  13. #13
    5 Star Lounger st3333ve's Avatar
    Join Date
    May 2003
    Location
    Los Angeles, California, USA
    Posts
    705
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Find Character Styles (Word 2000 SR-1)

    I don't know that you can have a direct-formatted property that is consistent with an active character style. That is, let's say you had a two-word phrase that was bold and underlined (direct-formatted), but then you applied a character style to the entire sentence that included bold. (Or reverse the order: you have a sentence that's formatted with a character style that includes bold, and then you select the two-word phrase and purport to apply bold as direct formatting.) In either case, I don't think Word stores any separate info that would let it know that those two particular words were bold in two different ways. Instead, I think Word just considers those two words bold as part of the character style. (As you may know, WordPerfect is different in this regard. It has, for example, "Ignore: Bold" codes that kick back to active "Bold" codes if some greater surrounding Bold zone is deleted.)

    Except for that little problem, though, I've done some experimenting and it looks like you may have stumbled onto a potentially useful technique. It looks like the reversion to Default Paragraph Font that happens when you completely delete a character style from a document leaves any direct formatting intact (subject to the complication in my first paragraph) -- unlike the annoying result when you try to use Find/Replace for the same purpose. At any rate, I tried it with a few different character styles and a variety of direct formatting and never lost any direct formatting that was inconsistent with the attributes of the character style.

    For cases where you only want to remove the character style from some places in the document and leave it in others, you could do a 4-step process where you first surrounded every instance of the character style with some kind of searchable marker pair, then deleted the style, then re-created the style, and finally re-applied the style on a case-by-case basis as Word searched through the document for those marker pairs.

    SUPPLEMENTAL NOTE (ADDED LATER): Um, however, Step 4 of my 4-step approach (re-applying the re-created style to selected locations) will likely blow out any direct formatting in those locations. So, for cases where you only want to remove the character style from some places in the document and leave it in others, see Andrew's posts in this same thread.

  14. #14
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find Character Styles (Word 2000 SR-1)

    Hi Rich,

    A "general purpose" macro that works always (= remove character style, but keep any manual formatting that was applied on top of the character style) would be great, but I never got around to writing one, and can't think of a good solution except Andrew's.
    It is a fine tool in any "toolbox".

    I don't often use "For Each myCharacter", since I usually deal with whole books, and it would be prohibitively slow.
    I usually tag the things I want to keep, using 3 "Find/Replace"s:

    Say,
    -- search for character style xy + bold, replace with ^&;
    -- then remove the character style (replace with Default Paragraph Font);
    -- then replace (*) with 1 and bold (using wildcards).

    The exact procedure/code would depend on the character style and the applied formatting.

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  15. #15
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: Find Character Styles (Word 2000 SR-1)

    Sorry for not replying sooner, but that may work because the direct formatting is pretty much always Bold+Underline or just Bold.

    Thx.

    -Rich

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •