Solved

Type excel.application is not defined

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

Expert Comment

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

Imports Microsoft.Office.Interop.Excel
0
 
LVL 74

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

16 Experts available now in Live!

Get 1:1 Help Now