PDA

View Full Version : Copy & paste



av8tordude
04-22-2011, 03:16 PM
I have a userform that will allow me to paste 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

Thanks for your help.

Kenneth Hobs
04-22-2011, 07:22 PM
Option Explicit

Private dataobj As New MSForms.DataObject

'http://www.vbaexpress.com/forum/showthread.php?t=37161
Private Sub CommandButton1_Click()

'put text on 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 tfAppend As Boolean, s As String
On Error GoTo ElseClause

s = dataobj.GetText(1)
tfAppend = s <> ""

If tfAppend Then
dataobj.SetText dataobj.GetText(1) & vbCrLf & TextBox1.Text
dataobj.PutInClipboard
MsgBox "Appended Copy"
Else
ElseClause:
dataobj.SetText TextBox1.Text
dataobj.PutInClipboard
MsgBox "Copied"
End If

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