Solved

Convert Listview to excel file (vb6)

Posted on 2007-11-15
6
2,926 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now