|
Subject:
|
how to export to excel
|
|
Posted By:
|
anjaneekumarcl
|
Post Date:
|
9/27/2004 1:57:31 AM
|
Please tell me how export the contents of Listbox to an Excel file using vb on click of the button.
Please Help ASAP.
|
|
Reply By:
|
Anantsharma
|
Reply Date:
|
9/28/2004 4:58:26 AM
|
HI,
Add Reference to Microsoft Excel Library whihcever is available
Public Sub WriteToExcel(Byval ExcelFileTOWriteIn as string) Dim ExcelApp As Excel.Application Dim WS As Excel.Worksheet Dim i As Long Dim RowNumAs long Dim stra As String Dim Strb as string Set ExcelApp = CreateObject("excel.application") ExcelApp.Workbooks.Open (ExcelFileTOWriteIn) Set WS = ExcelApp.ActiveWorkbook.Sheets("Sheet1") RowNum=1 For i=0 to List1.listcount-1 stra="a"+cstr(Rownum) WS.Range(stra).value=Trim(List1.list(i)) RowNum = RowNum + 1 Next i ''Release all the objects u have created.... End Sub
Above code will write all the items from List box to clumn a of excel (a1, a2, a3 etc)
Hope this helps
B. Anant
|
|
Reply By:
|
anjaneekumarcl
|
Reply Date:
|
9/29/2004 4:13:23 AM
|
thanx Anant
I will try and let you know
|