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!

using VB2005 with Excel 2007...

Status
Not open for further replies.

dtvonly

Technical User
Jan 3, 2008
8
US
Dim objExcel As New Excel.Application
Dim objWorkbook As Excel.Workbook
Dim objSheet As Excel.Worksheet
objExcel.Visible = True
objWorkbook = objExcel.Workbooks.Open("c:\Dat.xlsx")
objWorkbook = objExcel.Workbooks.Add()
objSheet = objWorkbook.Worksheets(1)
objSheet.Cells(2, 2).Value = "something"

VB2005.net is complaining of:
Type Excel.Application is not define
Type Excel.Workbook is not define
Type Excel.Worksheet is not define

I have added the Microsoft Excel V12.0 object library reference.
My Dat.xlsx is a simple 2 rows by 5 columns of numbers, no empty cell.

Please help. Thank you.
 

At the very top of the code, put:

Imports Microsoft.Office.Interop

to import the namespace that contains the Excel.Workbook and Excel.Worksheet classes.


OR, you could create the Office objects with the namespace:

Dim objExcel As New Microsoft.Office.Interop.Excel.Application
Dim objWorkbook As Microsoft.Office.Interop.Excel.Workbook
Dim objSheet As Microsoft.Office.Interop.Excel.Worksheet


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top