Log in

View Full Version : [SOLVED:] Pasting Text Data Into a Textbox on a Multipage Form



Rob342
03-20-2018, 06:09 AM
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

SamT
03-20-2018, 10:17 AM
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

Rob342
03-20-2018, 12:38 PM
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

snb
03-20-2018, 01:05 PM
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.

Rob342
03-20-2018, 02:04 PM
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

SamT
03-20-2018, 02:38 PM
Using the Clipboard might work :dunno:

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

snb
03-21-2018, 02:02 AM
Sub M_snb()
with getobject("G:\OF\example.docx")
userform1.textbox301.text=.paragraphs(2).range.text
end with
End Sub

Rob342
03-21-2018, 02:13 AM
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

snb
03-21-2018, 03:30 AM
I wouldn't mind if this thread was moved again to the spot where it had been placed originally.:yes

Rob342
03-21-2018, 05:00 AM
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

snb
03-21-2018, 05:53 AM
Them moderators:crying: ;)