Results 1 to 4 of 4

Thread: Tricky MS Word interacting with VB App question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    New York
    Posts
    165

    Question Tricky MS Word interacting with VB App question

    Is there a way of keeping track of content copied from a Word document into a RTB on a VB Form?

    I am creating an application where the user clicks on a Command Button which then populates a RTB with the content from the MS Word document.

    I need the user to then be able to highlight a section of text within the RTB, click a 'Covert Text to Heading1' button and then see the same text within the Word document converted to the Heading1 style.

    I have been trying for ages to get something going, but am having difficulty relating what is selected in the RTB to the same text in the Word document.

    Any ideas would be much appreciated

    Thanks,

    Chris

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    New York
    Posts
    165
    Anybody?? Please!!!

  3. #3
    WorkHorse
    Guest
    You have the whole document text in the RTB, right? Then it would be something like this:

    VB Code:
    1. Dim MyRange As Range
    2.     'Start of range = RichTextBox1.SelStart
    3.     'End of Range = RichTextBox1.SelStart + RichTextBox1.SelLength
    4.     Set MyRange = ActiveDocument.Range(RichTextBox1.SelStart, RichTextBox1.SelStart + RichTextBox1.SelLength)
    5.     MyRange.Select
    6.    
    7.     'To use Word constant styles
    8.     Selection.Style = -2 'wdStyleHeading1 constant
    9.    
    10.     'or to use the styles associated with a document
    11.     'Selection.Style = ActiveDocument.Styles("Heading 1")

    That matches the RTB selection range to the Word document range. You probably don't need to use a range. I guess you could do this:

    VB Code:
    1. ActiveDocument.Range(RichTextBox1.SelStart, RichTextBox1.SelStart + RichTextBox1.SelLength).Select
    2.     Selection.Style = -2 'wdStyleHeading1 constant

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    New York
    Posts
    165
    Thanks! I'll give it a go

Posting Permissions

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



Click Here to Expand Forum to Full Width