Solved

Convert Listview to excel file (vb6)

Posted on 2007-11-15
6
3,030 Views
Last Modified: 2008-02-01
Hi,
 How do I convert listview to excel file

Thx.
0
Comment
Question by:madmare
[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
  • 3
  • 2
6 Comments
 
LVL 13

Expert Comment

by:hiteshgoldeneye
ID: 20287715
use the following code

 Dim xlApp as Object,xlBook as Object,xlsheet as Object, i as Integer
   Set xlApp = New Excel.Application
    Set xlBook = xlApp.Workbooks.Open(App.path & "\ListBook1.xls") 'to open the workbook
    Set xlsheet = xlBook.Worksheets.Item(1) 'to select the sheet within the workbook
For i=0 to List1.ListCount-1
    xlsheet.Cells(i,1)=List1.Items(i)
Next
xlBook.Close savechanges:=true
xlApp.Quit
0
 

Author Comment

by:madmare
ID: 20287749
in my listview I don't have the proporites "ListCount" & "Items"

I am useing VB6

0
 
LVL 13

Expert Comment

by:hiteshgoldeneye
ID: 20287764
Can you elaborate which control you are using and which development environment?
0
Technology Partners: 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!

 

Author Comment

by:madmare
ID: 20287864
I am using ListView object in VB6 windows application
0
 
LVL 13

Expert Comment

by:hiteshgoldeneye
ID: 20288086
'ok try this then
Dim xlApp As Object, xlBook As Object, xlsheet As Object, i As Integer
   Set xlApp = New Excel.Application
    Set xlBook = xlApp.Workbooks.Open(App.Path & "\ListBook1.xls") 'to open the workbook
    Set xlsheet = xlBook.Worksheets.Item(1) 'to select the sheet within the workbook
For i = 0 To ListView1.ListItems.Count - 1
    xlsheet.Cells(i, 1) = ListView1.ListItems(i)
Next
xlBook.Close savechanges:=True
xlApp.Quit
0
 
LVL 26

Accepted Solution

by:
EDDYKT earned 500 total points
ID: 20288455
Dim xlApp As Object, xlBook As Workbook, xlsheet As Object, i As Integer
    Dim s As String
    Dim lst As ListItem, lst1 As ListSubItem, row As Integer, col As Integer
   
    Set xlApp = New Excel.Application
    Set xlBook = xlApp.Workbooks.Add 'creates a blank workbook
    Set xlsheet = xlBook.Worksheets.Item(1) 'to select the sheet within the workbook
   
    row = 1
    col = 1
    For i = 1 To ListView1.ColumnHeaders.Count
        xlsheet.Cells(row, col) = ListView1.ColumnHeaders(i)
        col = col + 1
    Next
    col = 1
    row = row + 1
    For Each lst In ListView1.ListItems
        col = 1
        xlsheet.Cells(row, col) = lst.Text
        col = col + 1
        For Each lst1 In lst.ListSubItems
            xlsheet.Cells(row, col) = lst1.Text
            col = col + 1
        Next
        row = row + 1
    Next
    xlBook.Close savechanges:=True, FileName:="c:\temp\test.xls"
    xlApp.Quit
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using "ScreenUpdating" 6 85
Excel - Save a copy of work book 13 96
passing a value with stream reader AFTER a ";" 3 91
Excel Automation VBA 19 116
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

732 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