Consulting

Results 1 to 4 of 4

Thread: how to format selectd characters which are not associated with a character style

  1. #1
    VBAX Regular
    Joined
    Oct 2010
    Location
    Berlin
    Posts
    46
    Location

    how to format selectd characters which are not associated with a character style

    Hello,

    I know that I can replace a certain character style with another one. But is there as well a possibiliity to replace within a selection only those characters which have NOT been associated with a character style? When I seach for the "Default Paragraph Font" all characters within the selection become changed.

    thank you very much in advance,
    Marcel

  2. #2
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    Sure-- just use a For...Loop for each character and test to see if the character style is applied. You can't, as you've discovered, use the Find object to do it in with a "Replace All" concept, the way you could for a paragraph style (i.e., find all "Normal" style paragraphs and replace with "Body Text" style).


    However, I almost don't understand this question. If you want to replace everything within the selection which is NOT formatted with a character style... why can't you just apply the character style to the selection?

    Are you trying to maintain existing direct formatting over top of the the existing character style? (i.e., you want to format everything with the "Emphasis" character style--which is normally italic--but any letters which have the "Emphasis" character style applied but which are also blue font color, need to be left alone?

    This is really granular and may indicate that the styles aren't being used properly in the template in the first place. In short-- it's a pretty accepted standard practice to either use direct formatting or use character styles. If you are co-mingling the two, you're basically just creating a confusing scenario for your end-users.

    Does this help answer your bigger question? (I'm assuming you don't need a sample of code to test each character in a selection, because that's not really the answer you're looking for).

  3. #3
    VBAX Regular
    Joined
    Oct 2010
    Location
    Berlin
    Posts
    46
    Location
    Hello Frosty,

    thanks for your answer.

    I have structured the text in question extensively and have hidden the structural elements. For various purposes I want to select certain passages of the text and assign a character style, but this style should not be applied to the hidden structural marks.

    I don't co-mingle styles and direct formatting. Actually this practice is one of my constant nightmares (I often have to work with a text in which this has been done).

    I agree, I can use a loop and check every character within the selection. The only setback here is that this way it is very cumbersome to undo the formatting of a lengthy passage should I decide that after all I don't want it at this very place... - Sure, I could, of course write an "undo"-loop, but I was looking for a more elegant solution.

    greetings,
    Marcel

  4. #4
    VBAX Master
    Joined
    Feb 2011
    Posts
    1,480
    Location
    You are, essentially, looking for an elegant way to deal with a group of custom ranges.

    What I have done in the past, is to create a class object which handles my custom ranges (I've never designed one which worked off the selection, always off of the active document) in a collection. I let the class take care of defining the ranges accurately.

    But it all depends on what you mean by "elegant."

    Since there is no way to programmatically create a non-contiguous selection (http://support.microsoft.com/?kbid=288424), you're left with creating your own elegance. If you're using Word 2007/2010, there is a new undo object which may very well be useful (allowing you to perform multiple actions, but only show a single custom action in the undo list).

    If you're using 2003, then the standard practice is to insert a bookmark at the beginning of your macro so that you can more accurately undo backwards until you hit the insertion of that bookmark.

    But you'd need to be more specific with the structure you're talking about, for me (or anyone) to give really specific advice (obviously, there are different ways to go about performing your actions, so perhaps if you show code, a suggestion can be given which will create less actions for the undo list).

Posting Permissions

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