View Full Version : [SOLVED:] Standard CTRL+C in ListBox
Shiftyshell
11-18-2020, 07:12 AM
Hi all,
I have created a UserForm with a ListBox. I would need to use the default CTRL + C to copy data from the ListBox. Is there such a possibility?
Thank you for your help in advance.
Seems related to your previous post. What is your outcome objective? Copy the listbox selection to where, or copy the whole listbox contents somewhere? Dave
Shiftyshell
11-18-2020, 10:16 AM
Yes, right, related to my previous post. Yes, right, related to my previous post. I want copy one value from listbox to web browser or to other applications.
You don't need to copy the selected value. For example, U can assign the selected listbox1 item in Userform1 to a variable as follows ...
Dim SomeVariableName as String
SomeVariableName = UserForm1.ListBox1.List(UserForm1.ListBox1.ListIndex)
You would then pass that value to your web browser or other application. HTH. Dave
Shiftyshell
11-18-2020, 11:01 AM
Need to paste the code into the UserForm code?
U can trial this...
Module code..
Public SomeVariableName as String
Userform code...
Private Sub ListBox1_Click()
SomeVariableName = UserForm1.ListBox1.List(UserForm1.ListBox1.ListIndex)
End Sub
If U select something in listbox1, you can then use the SomeVariableName for whatever U want. U can even close the userform and the Variable value will persist (if U have placed the variable declaration at the top of a module as indicated). Dave
Shiftyshell
11-18-2020, 02:01 PM
Thanks for help. I solved problem again with button and code:
Private Sub CommandButton4_Click()
Dim clipboard As MSForms.dataObject
Dim strSample As String
Set clipboard = New MSForms.dataObject
strSample = UserForm1("ListBox1").Value
clipboard.SetText strSample
clipboard.PutInClipboard
End Sub
It can be done more concisely:
Private Sub ListBox1_Click()
With GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
.SetText ListBox1
.PutInClipboard
End With
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.