Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add selected list box items to clipboard 1

Status
Not open for further replies.

bakerm

Programmer
Apr 25, 2000
53
0
0
US
Does anyone know the best way to add the selected items from a list box to the clipboard? I am using a List Box control with MultiSelect set to 2-Extended. This will allow the user to select multiple items.

Any help will be greatly appreciated!

Thanks!
 
try the following:

Clipboard.Clear
Clipboard.SetText lst1.Value
 
If you are working with a regular listbox, it doesn't have a .value property. Chris, you might be getting that from vba? Below is code for getting all of the selected items from list1, then moving them to list 2 via the clipboard. It can be done directly(bypassing the clipboard step) so this isn't really something you might actually do, but it is a good example of getting all of the selected items into and out of the clipboard.
Code:
Private Sub Command1_Click()
    Dim i As Integer
    
    List2.Clear
    Do Until i = (List1.ListCount)
       Clipboard.Clear
       If List1.Selected(i) = True Then
          Clipboard.SetText List1.List(i)
          List2.AddItem Clipboard.GetText
       End If
       i = i + 1
    Loop
End Sub
Hope that helps!
 
If I understand correctly, you want all selected items to land on the clipboard at once. Something like this should work.

Dim i As Integer
Dim strClip As String

strClip = ""

With List1
For i = 0 To .ListCount - 1
If .Selected(i) Then strClip = strClip & .List(i) & vbNewLine
Next i
End With

If strClip <> &quot;&quot; Then
Clipboard.Clear
Clipboard.SetText strClip
End If

Hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top