Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Nov 2001
    Posts
    119
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Selected text - Can i tell what the styles are? (Word 2002)

    Hi,

    I have some code that intercepts the copy command in Word. If a user selects some text which contains more than one styles, the Selection.Style command fails and I get an error. This is becuase more than one styles exists within the selected text.

    Is there any way to determine what styles are in the selected text?

    Any advice really would be much appreciated as this is pretty urgent.

    Thanks, Chris

  2. #2
    Star Lounger
    Join Date
    Jun 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Selected text - Can i tell what the styles are? (Word 2002)

    How about cycling thro' the paragraphs in the selection and setting each separate para to the required style?

  3. #3
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts

    Re: Selected text - Can i tell what the styles are? (Word 2002)

    <pre>Dim aPara As Paragraph
    For Each aPara In Selection.Paragraphs
    MsgBox aPara.Style
    Next aPara</pre>

    This won't tell you the character styles applied though
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  4. #4
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Selected text - Can i tell what the styles are? (Word 2002)

    Chris,

    Following on from Andrew's comment, if you only need to detect paragraph styles, that can be quite quick using a For Each loop, but if you need to detect character styles also (which I'd think you should), then you need to loop through every character in the selection, which is going to be unacceptably slow.

    What is it you're trying to achieve? - maybe there is another way to approach it.

    Gary

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

    Re: Selected text - Can i tell what the styles are? (Word 2002)

    An alternative to stepping through every character would be to use find to search for every character style. Which is quicker would depend on the size of the selection and the number of defined character styles.

    StuartR

Posting Permissions

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