devxlogo

Copy Listview Contents to a Clipboard

Copy Listview Contents to a Clipboard

This easy routine copies the contents of a listview, including column headers, to the clipboard for pasting into Excel or other applications:

 Public Sub SendToClipboard(ByVal ListViewObj _As MSComctlLib.ListView)Dim ListItemObj As MSComctlLib.ListItemDim ListSubItemObj As MSComctlLib.ListSubItemDim ColumnHeaderObj As _MSComctlLib.ColumnHeaderDim ClipboardText As StringDim ClipboardLine As StringClipboard.ClearFor Each ColumnHeaderObj In _ListViewObj.ColumnHeadersSelect Case ColumnHeaderObj.IndexCase 1ClipboardText = ColumnHeaderObj.TextCase ElseClipboardText = ClipboardText & _vbTab & ColumnHeaderObj.TextEnd SelectNext ColumnHeaderObjFor Each ListItemObj In _ListViewObj.ListItemsClipboardLine = ListItemObj.TextFor Each ListSubItemObj In ListItemObj.ListSubItemsClipboardLine = ClipboardLine & _vbTab & ListSubItemObj.TextNext ListSubItemObjClipboardText = ClipboardText & vbCrLf _& ClipboardLineNext ListItemObjClipboard.SetText ClipboardTextEnd Sub

devx-admin

Share the Post: