Consulting

Results 1 to 8 of 8

Thread: Standard CTRL+C in ListBox

  1. #1
    Banned VBAX Regular
    Joined
    Nov 2020
    Location
    https://t.me/pump_upp
    Posts
    21
    Location

    Standard CTRL+C in ListBox

    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.

  2. #2
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    832
    Location
    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

  3. #3
    Banned VBAX Regular
    Joined
    Nov 2020
    Location
    https://t.me/pump_upp
    Posts
    21
    Location
    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.

  4. #4
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    832
    Location
    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

  5. #5
    Banned VBAX Regular
    Joined
    Nov 2020
    Location
    https://t.me/pump_upp
    Posts
    21
    Location
    Need to paste the code into the UserForm code?

  6. #6
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    832
    Location
    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

  7. #7
    Banned VBAX Regular
    Joined
    Nov 2020
    Location
    https://t.me/pump_upp
    Posts
    21
    Location
    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

  8. #8
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,635
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •