User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 401,595 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,690 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.

Export Data from listbox to Excel

Join Date: Nov 2007
Location: ★ Jogja ★
Posts: 2,473
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Rep Power: 9
Solved Threads: 215
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Nearly a Posting Maven

Re: Export Data from listbox to Excel

  #4  
May 11th, 2008
oh... i m so sorry...
yeah that codes for vb 6, but there are same code for vb.net.
this following code for vb.net.
  1. Dim MsExcel As Excel.Application
  2.  
  3. Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4. MsExcel = CreateObject("Excel.Application")
  5. End Sub
  6. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  7. With ListBox1.Items
  8. .Add(txtName.Text)
  9. .Add(txtEmail.Text)
  10. .Add(txtMobile.Text)
  11. End With
  12. End Sub
  13.  
  14. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  15. MsExcel.Workbooks.Add()
  16. MsExcel.Range("A1").Value = txtName.Text
  17. MsExcel.Range("B1").Value = txtEmail.Text
  18. MsExcel.Range("C1").Value = txtMobile.Text
  19. MsExcel.Visible = True
  20. End Sub
- button 1 for add item from textbox to listbox.
- button 2 to add all item in listbox to excel.
- Declare Dim MsExcel As Excel.Application in top of all event. don't declare it on event cause it be a global variable.
- You can modified it as u needed.
Last edited by Jx_Man : May 11th, 2008 at 5:32 am.
Attached Images
File Type: jpg Export to Excel .net.JPG (78.3 KB, 3 views)
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote  
All times are GMT -4. The time now is 4:49 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC