Consulting

Results 1 to 11 of 11

Thread: Pasting Text Data Into a Textbox on a Multipage Form

  1. #1
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location

    Pasting Text Data Into a Textbox on a Multipage Form

    Hi

    Does anybody know of a routine where you can paste data into a textbox on a multipage form or even if this is possible
    The data could be text on a word doc or excel spreadsheet or simply from a text file

    So the theory is the user copies data from ? and then be able to paste it into a textbox on the multipage form ?

    Rob

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    PasteText = "AJdnduAmdirn"
    UserForm1.Multipage1.Pages(1).TextBox1.Text = PasteText
    With UsreForm1
       With .MultiPage1
          With .Pages1
              With .TextBox1
                  .Text = PAsteText
              End With
          End With
       End With
    End With
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    Hi Sam
    Thanks for reply, didn't explain very well.
    What the user wants to do is select text from say a word doc and with the user form running is to paste that text from the mouse into the text box.
    Rob
    Last edited by Rob342; 03-20-2018 at 12:56 PM.

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    The user shouldn't copy, to select the text should be sufficient:

    In VBA:

    Userform1.Textbox301.text=selection.text
    Although Textbo301 may be locateed in page3 of a multipage, you can address it directly.

  5. #5
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    Hi snb
    This works if the text is in the same excel spreadsheet but does not do anything if text is selected in a word doc is it possible to paste directly into a textbox from right clicking with a mouse 0r not ?
    Rob

  6. #6
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Using the Clipboard might work :

    Straight from the UserForms Help file
    Dim MyData as DataObject

    MyData.GetFromClipboard
    TextBox1.Text = MyData.GetText(1)

    I would place that in the TextBoxes's doubleClick Event Sub
    Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    Dim MyData as DataObject  
    
    MyData.GetFromClipboard
    TextBox1.Text = MyData.GetText(1)
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  7. #7
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    Sub M_snb()
       with getobject("G:\OF\example.docx")
             userform1.textbox301.text=.paragraphs(2).range.text
       end with
    End Sub

  8. #8
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    Hi Sam
    Was getting error code 91 but revamped as code below, It is working via the Dbl_Click event NB Vbax not allowing code tags or pasting of code will try again later
    Last edited by Rob342; 03-21-2018 at 02:20 AM. Reason: code tags not working & Paste not working

  9. #9
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    I wouldn't mind if this thread was moved again to the spot where it had been placed originally.

  10. #10
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    Hi snb
    Don't know why they moved it ?
    Have tried your code works ok with a couple of tweeks
    Sub M_snb() with getobject("G:\OF\example.docx") textbox301.text=.paragraphs(2).range.text end with End Sub
    SAMT
    This works as well
    Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) Dim clipboard As MSForms.DataObject Set clipboard=New MSForms.DataObject clipboard.GetFromClipboard TextBox1.Text = clipboard.GetText(1) End Sub
    Have found a routine on Andy Popes website where you can paste directly into a textbox
    here the link
    http://www.andypope.info/vba/uf_contextualmenu.htm

    Rob
    Last edited by Rob342; 03-21-2018 at 06:02 AM.

  11. #11
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    Them moderators

Posting Permissions

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