Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Location
    Upstate NY, New York, USA
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Apply font attributes to string (VB/Word 97)

    This novice writes:

    I have the following code and need to apply bold, small caps to "frmDeed.TextBox4.Text" only....

    ActiveDocument.Variables.Add Name:="AddSellerAddress", Value:=" and " & _
    frmDeed.TextBox4.Text & ", residing at " & frmDeed.TextBox5.Text & ", " & frmDeed.TextBox6.Text

    I've tried a few things but can't seem to get it. Thank you for your advice.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Apply font attributes to string (VB/Word 97)

    A document variable is (in Word 97 at least) just a string, with no formatting.
    If you want to store formatted text, consider the use of AutoText fragments.

  3. #3
    Star Lounger
    Join Date
    Jan 2001
    Location
    Upstate NY, New York, USA
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Apply font attributes to string (VB/Word 97)

    But I don't know what will be contained in TextBox4...if anything. I'm using autotext throught the process, but how would I use autotext in this instance?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Apply font attributes to string (VB/Word 97)

    I haven't really thought this through. Usually, you use predefined AutoText entries. But you can also create and modify them in code.
    In the code you tried, you store some text in a document variable using code. Instead of that, you could use code to store the text (including the contents of TextBox4 and the desired formatting) in an AutoText entry.
    Perhaps somebody will come up with better ideas if you explain what you want to do with this.

  5. #5
    Star Lounger
    Join Date
    Jan 2001
    Location
    Upstate NY, New York, USA
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Apply font attributes to string (VB/Word 97)

    Thank you Hans. I'm just inserting some variable information in the middle of a paragraph, but the Seller's name should be bold, small caps, and the rest normal text. There may or may not be a second Seller, but if there is, I wanted it to be formatted with those font attributes.

  6. #6
    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: Apply font attributes to string (VB/Word 97)

    Best might be to have some placeholder text there, such as *JoanneTextHere* that is styled as you want the inserted text to be styled. If you then select the placeholder and use Selection.TypeText to replace it with the contents of your text string, it should take on the font attributes of what it replaces. Alternatively, you could use Replace, if the placeholder is guaranteed to be unique.

  7. #7
    Star Lounger
    Join Date
    Jan 2001
    Location
    Upstate NY, New York, USA
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Apply font attributes to string (VB/Word 97)

    Thank you! That got me on the right track. I just had to break out the original string a little more.... here's the code that worked for me:

    Selection.GoTo what:=wdGoToBookmark, Name:="Seller2"
    Selection.TypeText ", and "
    With Selection.Font
    .Name = "Times New Roman Bold"
    .Bold = True
    .SmallCaps = True
    End With
    Selection.TypeText frmDeed.TextBox4.Text
    With Selection.Font
    .Name = "Times New Roman"
    .Bold = False
    .SmallCaps = False
    End With
    ActiveDocument.Variables.Add Name:="AddSellerAddress", Value:=", " & _
    "residing at " & frmDeed.TextBox5.Text & ", " & frmDeed.TextBox6.Text

    I very much appreciate your help. Sometimes I think I make things more difficult than they have to be....

Posting Permissions

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