Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Type excel.application is not defined

Posted on 2012-03-16
4
Medium Priority
?
660 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
  • 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 1500 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

Industry Leaders: 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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

824 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