Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > How to display excel data in VB


Reply
 
Thread Tools Display Modes
  #1  
Old 04-02-2003, 12:27 AM
epl_leicester epl_leicester is offline
Newcomer
 
Join Date: Apr 2003
Posts: 6
Unhappy How to display excel data in VB


Hi, can anybody teach me how to display the datas in Excel in the listboxes? (Any better advice to display the datas are welcome) Please reply if anybody has solution. Thankz a Million times
Reply With Quote
  #2  
Old 04-02-2003, 02:43 AM
JordanChris JordanChris is offline
Senior Contributor

* Expert *
 
Join Date: Jan 2003
Location: Newbury, UK
Posts: 1,092
Default

You need a reference in your VB environment to Microsoft Excel.

Then try this code to take data from Excel back into VB. hen modify it for your needs:
Code:
Private Sub Command1() Dim lRow As Long, lCol As Long, dValue As Double, dYear As Integer, dID As String Dim obExcelApp As Excel.Application Dim obWorkBook As Excel.Workbook Dim c As Excel.Range Set obExcelApp = CreateObject("Excel.Application") Set obWorkBook = obExcelApp.Workbooks.Open("C:\temp\temp.xls") For Each c In Excel.ActiveSheet.UsedRange dValue = c.Value MsgBox dValue ' Just show the data Next c Set obWorkBook = Nothing Set obExcelApp = Nothing End Sub
Reply With Quote
  #3  
Old 04-03-2003, 01:02 AM
epl_leicester epl_leicester is offline
Newcomer
 
Join Date: Apr 2003
Posts: 6
Default

Hi JordanChris, thanks for your help... Since I can now load data, do you have any idea on how to add,edit and delete a data using VB on Excel? I have totally no idea and even referring to books, I had yet to learn anything from the sources...
Reply With Quote
  #4  
Old 04-03-2003, 02:10 AM
JordanChris JordanChris is offline
Senior Contributor

* Expert *
 
Join Date: Jan 2003
Location: Newbury, UK
Posts: 1,092
Default

To put something back into Excel, you can use this code. Further details at www.MrExcel.com.
Code:
'Reference Microsoft Excel 8.0 Library Object or up Sub Main() Dim appExcel As Excel.Application Set appExcel = New Excel.Application 'PURPOSE: This will turn off all dialog box appExcel.DisplayAlerts = False 'PURPOSE: This will make it run in the background appExcel.Visible = False appExcel.ScreenUpdating = False 'PURPOSE: This will Open myfile.xls appExcel.Workbooks.Open FileName:="C:\myfolder\myfile.xls" appExcel.Worksheets("pSheet").Select 'PURPOSE: This will send data to a particular Range appExcel.Range("A4").Value = "help me" appExcel.Range("A5").Value = "please" 'PURPOSE: This will save workbook and close appExcel.ActiveWorkbook.Close Savechanges:=True 'PURPOSE: This will quit Excel appExcel.Quit 'PURPOSE: This will kill the instance Set appExcel = Nothing End Sub
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing data from excel to SQL server using VB jollyguy4all Database and Reporting 3 03-26-2003 05:07 AM
Using VB to extract data from an Excel sheet and graph it Lewis Word, PowerPoint, Outlook, and Other Office Products 1 10-09-2002 08:47 AM
QB to VB Conversion - By AIO BillSoo Tutors' Corner 0 08-06-2002 11:37 AM
To display data from excel in vb edmunddo_01 Word, PowerPoint, Outlook, and Other Office Products 1 07-02-2002 08:33 PM
How to use EXCEL data in VB suresh General 1 01-26-2001 01:17 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->