CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: ListView

  1. #1
    Join Date
    Oct 1999
    Posts
    10

    ListView

    How do u place what you have in listview into excel. Do u need to use OLE? Please help i'm in dire strays.....see I can't even spell...help fast


  2. #2
    Join Date
    May 1999
    Posts
    3,332

    Re: ListView

    this code has been tested in VB 6 and NT 4


    private Sub Command1_Click()
    Dim i as ListItem
    Dim j as Integer
    for j = 1 to 5
    set i = l.ListItems.Add
    i.Text = "col1"
    i.SubItems(1) = "col2"
    i.SubItems(2) = "col3"
    next j
    Dim x as Excel.Application
    set x = CreateObject("Excel.Application")
    Dim w as Excel.Workbook
    set w = x.Workbooks.Add
    x.Visible = true
    Dim row
    Dim col
    Dim strRange as string
    for row = 1 to l.ListItems.Count
    strRange = "A" & row
    w.ActiveSheet.Range(strRange).Value = l.ListItems(row).Text
    for col = 1 to l.ColumnHeaders.Count - 1
    strRange = Chr(Asc("A") + col) & row
    Debug.print strRange
    w.ActiveSheet.Range(strRange).Value = l.ListItems(row).SubItems(col)
    next
    next
    End Sub



    it adds a few lines to a list view (reportmode) and transfers the data to excel.
    There may be more efficient methods, but it works.


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured