Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Jan 2005
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    multiple styles in string (VBA/Word/2003)

    Using VBA in Word 2003, I need to produce a string that contains text in more than 1 paragraph style, ie:

    strToBeInserted = strInStyleAlreadyDefinedForTheParagraph & Chr$(13) & _
    strInAnotherParagraphStyle

    Can anyone point me to the correct coding? Or should I try another way around the problem?

    Ap

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,808
    Thanks
    4
    Thanked 236 Times in 218 Posts

    Re: multiple styles in string (VBA/Word/2003)

    A string variable has no style associated with it so you will need to find another way of asking this question.

    You could use a string which includes formatting codes to be parsed later to apply the styles but I guess we need to know what you are trying to achieve to make suggestions on how best to do this.

    For example, one suggestion might be to store the text formatted as an autotext entry and then just insert that when you need it.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    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: multiple styles in string (VBA/Word/2003)

    <pre> Selection.TypeText "End of existing paragraph."
    Selection.TypeParagraph
    Selection.Style = ActiveDocument.Styles("NameOfNewStyleGoesHere")
    Selection.TypeText "Start of new paragraph in a different style."
    </pre>


  4. #4
    New Lounger
    Join Date
    Jan 2005
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: multiple styles in string (VBA/Word/2003)

    Thanks for both responses. As I suspected, I was asking the wrong question. I have now inserted the relevant bits of text, and then selected them for application of styles. I was trying to do 2 things together (ie inserting a string and formatting text) when they needed to be done separately.

    Ap

Posting Permissions

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