Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read\write data to excell

Status
Not open for further replies.

unixisbest

Technical User
Jul 11, 2005
28
Hi VB Geniuses,

All i want to do is read data from in an excell sheet by VB programme. I have already wrote the codes but only thing i don`t know is how to get data from Excell.Users will be adding some data into excell and i need to get them by a VB programme. It`s will be like below:


open worksheet in `c:\xxxx.xls as input
if the date is today
find the date field`in worksheet and get data

Thanks for any help
 
Hi!
First add Microsoft Excel 10.0 Object Library from references.
I'm sure this code will help you.

Code:
Dim my_ObjExcel As New Excel.Application
Dim my_wbk As Excel.Workbook
Dim my_wks As Excel.Worksheet
Private Sub Command1_Click()
Dim x As String


x = Range("A1").Formula


End Sub

Private Sub Command2_Click()
my_wbk.Close
End Sub

Private Sub Form_Activate()
Set my_wbk = my_ObjExcel.Workbooks.Open("C:\sl.xls")
my_wbk.Sheets(1).Select
my_ObjExcel.Visible = False
End Sub
 
I have found that although it's great to be able manipulate Excel from VB completely, it is just as easy (if not easier) and more flexible to manipulate Excel from Excel using VBA. This does not apply to all projects, of course, but I often find that instead of writing a million lines of code in VB to access and alter an empty/almost empty excel sheet, it is easier to write just the code to gather and send the info to Excel and then have Excel go at it, digest it and display it. This allows you to leave your exe alone and simply alter the Excel file when something has to change with the report.
-Max
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top