|
-
Jun 4th, 2002, 11:14 PM
#1
Thread Starter
New Member
using excel in vb 6
hi! i wanted to know if it is possible to open an excel file in vb, access the cells and get its values. hope you can help me. i really, really need your help. thanks a lot.
-
Jun 4th, 2002, 11:37 PM
#2
Hyperactive Member
If you have excel on your computer then in VB click on Project,
Select References and check Microsoft Excel 5.0/9.0 whatever.
This is from MSDN:
CreateObject Function Example
This example uses the CreateObject function to set a reference (xlApp) to Microsoft Excel. It uses the reference to access the Visible property of Microsoft Excel, and then uses the Microsoft Excel Quit method to close it. Finally, the reference itself is
released.
Code:
Dim xlApp As Object ' Declare variable to hold the reference.
Set xlApp = CreateObject("excel.application")
' You may have to set Visible property to True
' if you want to see the application.
xlApp.Visible = True
' Use xlApp to access Microsoft Excel's
' other objects.
xlApp.Quit ' When you finish, use the Quit method to close
Set xlApp = Nothing ' the application, then release the reference.
PS. Make sure you set your objects=nothing, otherwise they'll
gang up on you. Hope this helps.
Sometimes what you're looking for is exactly where you left it.
-
Jun 4th, 2002, 11:50 PM
#3
Hyperactive Member
you could either use filesystemobject if you just want to read or use the automation method as described by johnvb6.
another method of starting excel
VB Code:
Dim objexcel As Excel.Application
Dim objbook As Excel.Workbook
Dm objsheet As Excel.Worksheet
Set objexcel = New Excel.Application
Set objbook = objexcel.Workbooks.Add
Set objsheet = objexcel.Worksheets.Add
the above is to create a new instance of excel. you can access the rows and columns using objsheet.cells(row,col) where row and col are integers.
to open an existing excel file use the following
VB Code:
Set objbook = objexcel.Workbooks.Open("filename")
-
Jun 5th, 2002, 12:32 AM
#4
Thread Starter
New Member
the codes given had really been very helpful. thanks a lot . I have another question though. Is there a way to know if the file ends or if it is the last row?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|