scratchpad

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,075
Office Version
  1. 2019
Platform
  1. Windows
I have a userform that will allow me to paste into a multi-line textbox with what I have copied to the clipboard. It works well, but can someone assist me with editing the code to allow me to append more copied text under the last copied text seperating each new paste with a space.

i.e.

Paste text 1

Paste text 2

Paste text 3

Code:
Private Sub CommandButton3_Click()

'Paste text from clipboard

'the following code must have a reference added for
'"Microsoft Forms 2.0 Object Library" in the project references.
    On Error GoTo My_Err
    Dim DataObj As New MSForms.DataObject
    DataObj.GetFromClipboard
    TextBox1.Text = DataObj.GetText
    MsgBox "Pasted"
    Exit Sub
My_Err:
    MsgBox "An Error occured when you tried to use the Clipboard. Make sure you have added a reference to MS Forms 2.0 Object Library: " & Err.Number & ":" & Err.Description
    
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
How about this?
Code:
TextBox1.Text= TextBox1.Text & DataObj.GetText
 
Upvote 0
Hi Norie

It doesn't insert a space below the previous pasted text and it doesn't appended the new text below the previous text.

i.e.

pasted text 1
[space] <= illustration only
pasted text 2
[space] <= illustration only
pasted text 3
 
Upvote 0
Ok...i got it.

I just insert this...

Code:
    If TextBox1 = "" Then
        TextBox1.Text = DataObj.GetText
    Else
        TextBox1.Text = TextBox1.Text & vbNewLine & _
        DataObj.GetText
    End If
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,519
Members
452,921
Latest member
BBQKING

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top