Consulting

Results 1 to 2 of 2

Thread: Copy & paste

  1. #1

    Copy & paste

    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.
    Attached Files Attached Files

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    [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
  •