Solved

Type excel.application is not defined

Posted on 2012-03-16
4
610 Views
Last Modified: 2012-03-19
Hi,

I'm using visual basic 2010, I'm trying to use excel from Vb.net but I keep getting the following error when using the following code: type excel.application is not defined

dim xl as excel.application
dim wb as excel.workbook
dim ws as excel.worksheet

I've added the following references:
Microsoft Excel 14.0 Object Library
Microsoft Office 14.0 Object Library
Microsoft visual basic for application s extensibility 5.3
micrisoft.office.interop.excel

and then imported the following :
Imports Microsoft.Office.Core
Imports Microsoft.Office.Interop
Imports System.Data

I use word without any issues :

Dim appWord As Word.Application
Dim docWord As Word.Document

How come excel doesn't work the same way?
0
Comment
Question by:FCapo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37729815
I believe you also need the import:

Imports Microsoft.Office.Interop.Excel
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37729826
Actually, strike that. I read your declarations incorrectly.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37730203
That is strange. It should work.

http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel(v=office.11).aspx

what happens if you import

Imports Microsoft.Office.Interop.Excel

and then use just application?
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 37732326
Is the last reference a mistake in your question? You should not reference the Interop, only Excel.

The Import is not an absolute condition, it simply enables you to use the classes in the library without having to give the namespace everytime. If the following is working, then simply adding an import to Microsoft.Office.Interop.Excel will enable you to use the syntax that you wanted:

Dim xl As Microsoft.Office.Interop.Excel.Application

But if this does not work, then your reference is not good.

Office applications are very touch about the version that is referenced. If the Excel version you have on the computer on which the application is running is not the same as the one you used for your reference, then you will end up with problems. You will have either to adjust the reference or use late binding (declaring variables as Object).
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question