Solved

Copy data out of a listview

Posted on 2004-04-05
2
316 Views
Last Modified: 2012-08-14
I want to be able to copy selected rows  or columns out a listview to the clipboard then be able to paste the resuts into excel and have the data inserted in the colums so it is formatted  the same way

so if the listview is like this
data 1 |  data2  | data 3
row2a |  data2  | data 3
 
I want to be able to highlight those 2 rows in the listview and copy them  then paste them into excel or whatever and have them formatted in the rows and colums that were in the listview.

Is there an easy way to do this?

Kelly



0
Comment
Question by:unreal400
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
plq earned 100 total points
ID: 10761045
           If Screen.ActiveControl Is lvw Then
                For Each itm In lvw.ListItems
                    If itm.Selected Then
                        sBuffer = sBuffer & Mid$(itm.Key, 2) & vbTab
                        For lCount = 0 To lvw.ColumnHeaders.Count - 1
                            If lCount = 0 Then
                                sValue = itm.Text
                            Else
                                sValue = itm.SubItems(lCount)
                            End If
                            sBuffer = sBuffer & sValue & vbTab
                        Next
                        sBuffer = sBuffer & vbCrLf
                    End If
                Next
            End If
           
            If sBuffer = "" Then
                MsgBox "No items are selected. Use CTRL and Click or Shift and Click to select the items you want to copy", vbExclamation
            Else
                Clipboard.Clear
                Clipboard.SetText sBuffer
            End If
0
 
LVL 14

Expert Comment

by:aelatik
ID: 10761101
Private Sub Form_Load()
    Clipboard.Clear
For i = 1 To 3
    ListView1.ListItems.Add , , "test"
    ListView1.ListItems.Item(i).SubItems(1) = "test1" & i
    ListView1.ListItems.Item(i).SubItems(2) = "test2" & i
Next i
   
    Dim BUFFER
    For i = 1 To ListView1.ListItems.Count
        BUFFER = BUFFER & ListView1.ListItems.Item(i).Text & vbTab & ListView1.ListItems.Item(i).SubItems(1) & vbTab & ListView1.ListItems.Item(i).SubItems(2) & vbCrLf
    Next i
        Clipboard.SetText BUFFER
End Sub
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question