Results 1 to 10 of 10
  1. #1
    Star Lounger
    Join Date
    Nov 2008
    Location
    England, Yate, Bristol
    Posts
    51
    Thanks
    4
    Thanked 0 Times in 0 Posts

    copy text in textbox and paste into a document (Of

    I can't believe this is so difficult. - I want to create a simple character counter for teacher's report comments. Everything is great except I cannot copy the text in VB and then paste it as text in another document. It keeps pasting the text box. I've tried all the help documents I can find, but none work.

    I would also like teachers to enter a student's name in a textbox and type a character like ^ and it be replaced with the student's name.

    Thanks for any guidance with this.

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

    Re: copy text in textbox and paste into a document (Of

    Welcome to Woody's Lounge!

    How are you copying the text? If you use something like

    Documents("Document1").Shapes("Text Box 1").TextFrame.TextRange.Copy
    Documents("Document2").Content.Paste

    you should paste only the text, not the text box.

    I'm not sure I understand your second question. You can create an AutoCorrect entry to have an abbreviation replaced automatically with a full name, or you can use Edit | Replace to do so.

  3. #3
    Star Lounger
    Join Date
    Nov 2008
    Location
    England, Yate, Bristol
    Posts
    51
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: copy text in textbox and paste into a document

    Thanks Hans. I tried using the code you suggested, but it doesn't copy. I get an error that the object is not found. Below is the code I used from you and below that is the original. I tried in a new document all the names were correct.

    Private Sub CommandButton1_Click()
    Documents("Document1").Shapes("TextBox1").TextFram e.TextRange.Copy
    End Sub

    My (not) working original code:

    Private Sub bttnCopy1_Click()

    'Documents("Document1").Shapes("Text Box 1").TextFrame.TextRange.Copy
    'Documents("Document2").Content.Paste

    Documents("WordCountv2").Shapes("txtReport2").Text Frame.TextRange.Copy
    'Documents("Document2").Content.Paste

    'txtReport2.SelStart = 0
    'txtReport2.SelLength = txtReport2.TextLength
    'txtReport2.Copy


    End Sub

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

    Re: copy text in textbox and paste into a document

    The code will only work with the correct name for the text box, of course. You can also use Shapes(1) or similar, using the correct index number for the text box.

  5. #5
    Star Lounger
    Join Date
    Nov 2008
    Location
    England, Yate, Bristol
    Posts
    51
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: copy text in textbox and paste into a document

    Sorry Hans, but I don't understand.

    This is the code I am using:

    Private Sub bttnCopy1_Click()

    Documents("WordCountv3").Shapes("txtReport2").Text Frame.TextRange.Copy

    End Sub
    The document is called WordCountv3 and the text box is called txtReport2

    I get an error 'Bad file name' with the line of code highlighted

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

    Re: copy text in textbox and paste into a document

    The "Bad file name" error indicates that the name of the document is not correct. What happens if you use Documents("WordCountv3.doc") ?

  7. #7
    Star Lounger
    Join Date
    Nov 2008
    Location
    England, Yate, Bristol
    Posts
    51
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: copy text in textbox and paste into a document

    I got excited there for a minute - - - but I got the error ' The item with the specified name was not found.' I checked and it is a .doc file.

    Documents("WordCountv3.doc").Shapes("txtReport2"). TextFrame.TextRange.Copy

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

    Re: copy text in textbox and paste into a document

    This means that the name of the document is OK now, but the name of the text box isn't correct.

  9. #9
    Star Lounger
    Join Date
    Nov 2008
    Location
    England, Yate, Bristol
    Posts
    51
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: copy text in textbox and paste into a document

    OK Hans Got it

    In the Word document, from the Developer tab I added an Active X Text box, which I could control through the Properties of the text box and all the time I was working with that.

    Now I just added a Text box through the Word Insert Text Box route, created a small macro and spotted that the Text Box number was 38. I added that to the Copy code and it now works.

    The only problem is I can't control the EnterKeyBehavior NOT to work (False), or can I?

    I would have preferred to use the Active X as I understand a little more of the VB for that. How, or can I get the copy text to work in the Active X Textbox?

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

    Re: copy text in textbox and paste into a document

    With an ActiveX control you can use something like this in the ThisDocument module of the document that contains the text box:

    Documents("OtherDocument").Content.InsertAfter Me.txtReport.Text

    or from a standard module

    Documents("OtherDocument").Content.InsertAfter ActiveDocument.txtReport.Text

Posting Permissions

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