Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 27th, 2004, 01:57 AM
Registered User
 
Join Date: Sep 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anjaneekumarcl
Default how to export to excel

Please tell me how export the contents of Listbox to an Excel file using vb on click of the button.

Please Help ASAP.

:(
 
Old September 28th, 2004, 04:58 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma
Default

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
 
Old September 29th, 2004, 04:13 AM
Registered User
 
Join Date: Sep 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anjaneekumarcl
Default

thanx Anant

I will try and let you know





Similar Threads
Thread Thread Starter Forum Replies Last Post
Export to excel moonbreeze Reporting Services 1 November 20th, 2006 08:42 PM
export to excel roy_mm Reporting Services 0 September 2nd, 2006 11:53 PM
Export to Excel using C# lily611 Crystal Reports 2 July 23rd, 2006 10:23 AM
excel export msrnivas Classic ASP Components 0 June 9th, 2004 10:15 PM
excel export msrnivas .NET Web Services 1 March 29th, 2004 03:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.