Solved

Convert Listview to excel file (vb6)

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

Thx.
0
Comment
Question by:madmare
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA saving file message display 5 66
VBA filters 2 61
Prevent checkbox click event occur while editing it in vb6 8 45
Publisher:   Unknown     VB.exe Application 1 21
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

773 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