Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert Listview to excel file (vb6)

Posted on 2007-11-15
6
Medium Priority
?
3,123 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
Industry Leaders: 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Suggested Courses

722 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