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

    Copy and paste paragraph from Word doc to RichTB? (Word 2002)

    Hi,

    I am developing an application that needs to be able to copy a paragraph of text from a Word document into the Rich Text Box, whilst maintaining the exact paragraph and font formatting etc. If I cut and paste using Ctl+C & Ctl+V, it seems to work fine. How can I replicate this using VBA?

    I have tried the following, but it doesn't work:

    Selection.Range.Copy
    RichTextBox1.TextRTF = Selection.Range.Paste

    Any help would be much appreciated [img]/forums/images/smilies/smile.gif[/img]

    Thanks, Chris

  2. #2
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copy and paste paragraph from Word doc to RichTB? (Word 2002)

    I've only dealt with complete documents before. I've used VBA to save the copmplete document as RTF, and then open the RTF.

    If the para has pictures in it though, it kills the performance.

    Is there a way of using VBA's "selection.copyformat" and "selection.copyformat"?

    Have you tried recording the actions and checking the VBA?

    (Sorry, I don't have Word available here)
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

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

    Re: Copy and paste paragraph from Word doc to RichTB? (Word 2002)

    Here is a kludge:

    <font face="Georgia">Selection.Copy
    RichTextBox1.SetFocus
    SendKeys "^v", True</font face=georgia>

    (Replace Selection by whatever range you want to copy, and RichTextBox1 by the name of your rich text box control)

    I know that SendKeys is frowned upon, but Microsoft itself uses it in MSKB article 193593 to paste into a rich text box control.

Posting Permissions

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