Copy data from excel listbox to clipboard

KUYJS

New Member
Joined
Sep 3, 2018
Messages
43
Hi,
I have one excel userform that has one listbox. I am adding 2 to 5 lines to it using Listbox1.Additem and once all items are added i want to copy this entire data to clipboard so that i may paste it to web based application uaing ctrl +v.

Kindly help
Regards,
Tarun
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Since there is a userform, and MSForms library is already loaded, MSForms.Dataobject can be used to interact with the clipboard.

Following code might give an idea.
Assuming there is a listbox called ListBox1, and items are already loaded.

Code:
Sub copyToClipboard()
Dim dataObject As New MSForms.dataObject
Dim tmpList As String
    ' Put the listbox items into a string, delimited with new line
    ' You can use another way for this, storing the data in the 
    'variable while your code is executing AddItem etc..
    With Me.ListBox1
        For i = 0 To .ListCount - 1
            tmpList = tmpList & .List(i) & vbCrLf
        Next i
    End With
    
    ' Use MSForms DataObject to send the variable data to the clipboard
    With dataObject
        .SetText tmpList
        .PutInClipboard
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,864
Messages
6,121,984
Members
449,058
Latest member
oculus

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