-
[VBA]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[/VBA]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules