Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    New Lounger
    Join Date
    May 2001
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Remove Character Style but Leave Manual Formatting (2000)

    OK, I know this sounds backwards from what we usually want users to do, but:

    * We have a character style for "Instructions" that is hidden, blue, italic text and used on templates. This is used for general instructions, as well as example text to be included in a document. This is handy because Show/Hide all quickly displays and hides all instructions. A macro is also used to find and remove instructions from finished docs.
    * We instruct people to use ctrl-spacebar to remove Instructions from example text that they will use.

    However, sometimes, there is manual formatting on bits of the text. For example, a super- or subscript, an italic phrase (latin words) and so on. These also get cleared with ctrl-spacebar. Applying the "Default Paragraph Font" style does the same thing.

    How can I slide the tablecloth of character styles out from underneath the china and silverware of manual formatting?

  2. #2
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remove Character Style but Leave Manual Formatting (2000)

    Instruct users on how to (or create a macro to) use Find/Replace to replace style "Instructions" with nothing.

    HTH,

    Chris

  3. #3
    New Lounger
    Join Date
    May 2001
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remove Character Style but Leave Manual Formatting (2000)

    Nope.
    If you find empty text with style "Instructions", replace with empty text and no style, you delete the text with that style.

    [By the way -- this trick does not work in '97: It does nothing at all! If you want to delete text with a particular style, you must replace it with something, like a known nonsense string, then delete the something]

    I'm sorry, you don't advance to the lightning round.
    Joel

  4. #4
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remove Character Style but Leave Manual Formatting (2000)

    I'm confused. You *don't* want to remove text with the character style from the document.

    Do you want to undo the character style without impacting manual formatting on other text in the paragraph?

    What about a macro that aplies the ctrl+spacebar only to the character style? Mind you, if they apply manual formatting to the character style, you'll lose it. But it's better than losing all manual formatting.


    <pre>Sub ResetCharacter()
    '
    Selection.Find.ClearFormatting
    With Selection.Find
    .Style = "instructions"
    .Wrap = wdFindContinue
    Do
    .Execute
    Selection.Font.Reset
    Loop Until .Found = False
    End With
    End Sub
    </pre>


    HTH,

    Chris

  5. #5
    New Lounger
    Join Date
    May 2001
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remove Character Style but Leave Manual Formatting (2000)

    Chris,
    That still doesn't do it: It removes all character formatting, styled and manual, from the text. I want to LOSE the character style, KEEP the manual formatting.

    A global search & replace isn't needed -- just on the current selection.

    Unfortunately, it's messy. If I could do something like this:
    set fsel = selection.font
    set fsty = activedocument.styles("Instructions").font
    set fdiff = fsel - fsty ' BLATANTLY ILLEGAL CODE
    selection.font.reset
    set selection.font = fdiff ' ALSO REALLY ILLEGAL

  6. #6
    Star Lounger
    Join Date
    Aug 2001
    Location
    St. Louis, Missouri, USA
    Posts
    67
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Remove Character Style but Leave Manual Formatting (2000)

    I'm not sure I understand whether you're trying to delete any text or just the styling.

    If it's just the style, can't you search for either the style name OR the specific specs you want to eliminate? For instance, if you want to keep the text but just not have it blue, search for just blue formatting and replace it with black. If you do it on just a selection and search Down, it'll stop at the end of the selection and ask whether you want to continue, and you can say No.
    You could do that with a macro. The catch is it will still have the character style, but it won't look like it. This would leave your manual coding intact.
    Or could you find the character style and replace it with another character style?

    Or is it more complicated?

    Lin

  7. #7
    New Lounger
    Join Date
    May 2001
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remove Character Style but Leave Manual Formatting (2000)

    All right, I explain. No. There is no time, I sum up. (from The Princess Bride)

    I have text with a character style called "instructions" which just happens to be hidden, blue and italic.
    Some of that text is also bold, superscripted, etc.

    I need to remove the Instructions style (not just the hidden, blue, italic) from it, without clobbering the manual formatting. Why can't I just add manual formatting to remove the hidden, blue italic? Because there are macros which are designed to delete anything with the Instructions style -- and I want to be able to use the Instructions to include example text that gets turned into 'real' text in the document.

  8. #8
    Star Lounger
    Join Date
    Aug 2001
    Location
    St. Louis, Missouri, USA
    Posts
    67
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Remove Character Style but Leave Manual Formatting (2000)

    So can't you just search for the style "Instructions" and replace it with another style called "Real" or "No longer instructions"? That should still preserve your manual formatting.

  9. #9
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remove Character Style but Leave Manual Formatting (2000)

    All I could think of off-hand was brute force. The replace with new character style seems much better.

    But, if you're interested, here's a snippet. You'd have to read into the array the font attributes you want to preserve. There's got to be a more elegant way, but I haven't found it. It'll be sloooooowww. Especially if you have a lot of text in that particular character style.

    <pre>Sub ResetCharacter()
    '
    Dim varFont(4)
    Dim oChar As Object
    Dim oStyle As Style

    For Each oChar In Selection.Characters
    If oChar.Style = "Testing" Then
    varFont(1) = oChar.Font.Bold
    varFont(2) = oChar.Font.Subscript
    varFont(3) = oChar.Font.Underline
    varFont(4) = oChar.Font.Superscript
    oChar.Font.Reset
    oChar.Font.Bold = varFont(1)
    oChar.Font.Bold = varFont(1)
    oChar.Font.Subscript = varFont(2)
    oChar.Font.Underline = varFont(3)
    oChar.Font.Superscript = varFont(4)
    End If
    Next
    MsgBox "Done"

    End Sub
    </pre>


  10. #10
    Star Lounger
    Join Date
    Aug 2001
    Location
    St. Louis, Missouri, USA
    Posts
    67
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Remove Character Style but Leave Manual Formatting (2000)

    OK, I'm almost illiterate in VBA, but I do a lot of searching and replacing. (I can do the search, but I'd be hard pressed to write the macro.)

    Why would you have to specify what attributes to preserve? Can't you just change the name of the style that's applied?

    This probably displays my appalling ignorance, but I'm really curious now.

    Lin

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Remove Character Style but Leave Manual Formatting (2000)

    There seem in theory to be several hard ways to do this, but the only easy one appears to be to wait until you've eliminated all the instances of Style

  12. #12
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Remove Character Style but Leave Manual Formatting (2000)

    Hi Lin,

    I agree. <img src=/S/smile.gif border=0 alt=smile width=15 height=15> That's why I said in the last post, "The replace with new character style seems much better. "

    I proposed the code as an exercise in near futility, as it's so inefficient. Hopefully, one of the VBA Gurus can come up with something else.

    Why come up with something else? JFinkle could create a new character style on which to base the replace. The old style had attributes of Hidden, Blue, and Italic. He creates a new character style of Not Hidden, Not Blue, and Not Italic. But, what if those attributes conflict with some of his paragraph styles? For example, an Italicized Heading style or a blue First Row Table style. In that case, the replace would cause problems with existing paragraph styles that had been modified with the old character style.

    When I said the code used brute-force I was being generous. One would have to read and assign every font attribute they were concerned about. It then examines every character in a selection and sez, "If you're the old character style, tell me everthing about the font I want to know, reset it to the paragraph style, and apply everything you told me about the font." Usable. But not fun.

    Chris

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

    Re: Remove Character Style but Leave Manual Formatting (2000)

    Below I have made a macro from the approach described by jscher2000.
    It removes the character style "Test" from selected text.
    To do that, it cuts the text, pastes it into a new dummy document where "Test" looks like "Default Paragraph Font", deletes the style "Test" from the new document, and pastes the text back after closing the dummy document.
    Very roundabout, but it seems to work, at least if the style isn't an in-built style (like "Emphasis"), or defined in Normal.DOT. Probably there are ways to make it work for all character styles, but for now, I'm out of ideas.

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

    <pre> Selection.Cut
    Documents.Add
    ActiveDocument.Styles.Add Name:="Test", _
    Type:=wdStyleTypeCharacter
    Selection.Paste
    ActiveDocument.Styles("Test").Delete
    Selection.WholeStory
    Selection.MoveEnd Unit:=wdCharacter, count:=-1
    Selection.Cut
    ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
    Selection.Paste</pre>


  14. #14
    New Lounger
    Join Date
    May 2001
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Nope, Nope, and Maybe

    Aside from the brute-force macro, and maybe the quarantine document, there doesn't seem to be an easy fix. Changing the character style still nukes the manual formatting applied to some of the text on top of the old style.

    It looks like something like this might be the best approach

    Sub ClearInstructions()
    Application.ScreenUpdating = False
    Selection.Copy
    Documents.Add "Normal.dot", , False
    Selection.Paste
    ActiveDocument.Styles("Instructions").Delete
    ActiveDocument.Select
    Selection.MoveEnd wdCharacter, -1
    Selection.Copy
    ActiveDocument.Close False
    Selection.Paste
    Application.ScreenUpdating = True
    End Sub

    It has an annoying screen flash (even with the ScreenUpdating off, and the "not visible" on the Documents.Add, and the text ends up not selected at the end. But it does appear that the quarantine approach works.

    Thanks,
    Joel

  15. #15
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Nope, Nope, and Maybe

    Aha! Now we're gettin' somewhere. Why use a dummy doc at all?

    <pre>ActiveDocument.Styles("Testing").Delete
    ActiveDocument.Styles.Add Name:="Testing", Type:=wdStyleTypeCharacter
    With ActiveDocument.Styles("Testing")
    .Font.Color = wdColorBlue
    '.Font.etc = whatever
    End With
    </pre>


Page 1 of 2 12 LastLast

Posting Permissions

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