Hi,
I have a listbox and i want users to be able to use the regular way of copy&paste.
When doing ctrl+c and ctrl+v im getting garbage
Is there a way to do so?
Thanks
There could be an easier way to do this but this was my quick-fix for it (needs to be "cleaned up" :
Public CtrlCode
' Fill some list box with data
Private Sub CommandButton1_Click()
ListBox1.AddItem "Test1"
ListBox1.AddItem "Test2"
ListBox1.AddItem "Test3"
ListBox1.AddItem "Test4"
ListBox1.AddItem "Test5"
End Sub
Private Sub ListBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
' Key_Down event traps only the first key in the Ctrl-C sequence (e.g. Ctrl). Use CtrlCode to flag that CTRL has been pressed while determining if the second key in sequence is "c" or "C".
' 17 is the key code for CTRL
If KeyCode = 17 Then CtrlCode = "Pressed"
End Sub
Private Sub ListBox1_KeyUp(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If CtrlCode = "Pressed" and KeyCode = 67 Then
Set MyData = New DataObject
MyData.SetText ListBox1.Text
' Copy data to clipboard
MyData.PutInClipboard
' Now that it is on clipboard, now able to
' paste "normally" using Ctrl-v.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.