Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    RichTextBox (VB6)

    Using a RichTextBox on a form, when transferring its contents to a word doc via code, I see the Return characters and the text doesn't wrap.

    Am I using the correct control for the right purpose ?

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

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

    Re: RichTextBox (VB6)

    Hi Dave,

    How do you transfer the text to Word? You should either save the contents to a RTF file using the SaveFile method, or take the TextRTF property and paste this into a Word document.

  4. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: RichTextBox (VB6)

    Hans

    I'm using a replace statement:-

    <pre> .Execute FindText:="#INDcomment#", ReplaceWith:=Me.RichTextBox1.Text, Replace:=2</pre>


    (P.s, The help last week, forgot to extend my thanks), Thanks.

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

    Re: RichTextBox (VB6)

    Try

    ..., Me.RichTextBox1.TextRTF, ...

    If that doesn't help, you'll probably have to use a different method.

  6. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: RichTextBox (VB6)

    Hans

    No, it doesn't work.
    Any other suggestions ?

  7. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: RichTextBox (VB6)

    I cannot test all this, so the following is just a guess. Try setting the FormattedText property of the selection or range found by the Execute method in Word (without ReplaceWith and Replace) to the TextRTF property of the RichTextBox control.

  8. #7
    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: RichTextBox (VB6)

    Or you could do a Replace() on the value from the rich edit control, swapping the chr(13) & chr(10) for ^p or a manual line break, whichever seems most appropriate to you. (The ^p would be for the Find and Replace dialog, not for directly assigning into the document.)

  9. #8
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: RichTextBox (VB6)

    Hans

    I'm not sure what you mean ?

  10. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: RichTextBox (VB6)

    Dave,

    Try this (again, it is "air code"):

    ...
    .Execute FindText:="#INDcomment#"
    If .Found = True Then
    appWord.Selection.FormattedText = Me.RichTextBox1.TextRTF
    End If
    ...

    where appWord is the Word application object (I assume you have some such variable)

  11. #10
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: RichTextBox (VB6)

    Thanks Hans

    Nice try, but bombed out.
    Back to the drawing board me thinks.

    Could a norma text box be used, multiline ?

  12. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: RichTextBox (VB6)

    If you don't need formatting such as bold or italic, a standard text box is *much* easier. The RichTextBox control is a bear to work with, frankly.

  13. #12
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: RichTextBox (VB6)

    It ain't my day !

    .Execute FindText:="#INDcomment#", ReplaceWith:=Trim(Me.txtComment.Text), Replace:=2

  14. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: RichTextBox (VB6)

    Hi Dave, try this (following Jefferson's suggestion):
    <code>
    .Execute FindText:="#INDcomment#", ReplaceWith:=Replace(Trim(Me.txtComment.Text), vbCrLf, "^p"), Replace:=2</code>

  15. #14
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: RichTextBox (VB6)

    Hans
    This is so close.

    This
    is
    a
    test

    Becomes

    This

    is

    a

    test

    Is this the closest you think we can get it?

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

    Re: RichTextBox (VB6)

    Dave,

    You'll have to experiment a bit. In the first place, can you verify that the space between the lines is caused by an empty paragraph? If so, try changing vbCrLf to vbCrLf & vbCrLf in the code.

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
  •