Thursday, 29 March 2018

VBA to copy text to clipboard | VBA program to copy text to clipboard

You can use below code to copy a text to clipboard.

Sub CopyToClipboard(strCopy As String)
On Error Resume Next
    Dim clipboard As MSForms.DataObject
    Dim strSample As String

    Set clipboard = New MSForms.DataObject
    clipboard.SetText strCopy
    clipboard.PutInClipboard
On Error GoTo 0
End Sub