Solved

Type excel.application is not defined

Posted on 2012-03-16
4
575 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

943 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now