Imports Excel = Microsoft.Office.Interop.Excel doesn't work

U

Uncle Martin

Hi,

I am trying to learn VSTO programming. I have Windows Vista installed.

When I type Imports Excel = Microsoft.Office.Interop.Excel, Intellisense
does not recognize anything after Microsoft. A green squiggly appears under
the statement. The tool tip says, "Namespace or type specified in the
Imports 'Microsoft.Office.Interop.Excel' doesn't contain any public member or
cannot be found. Make sure the namespace or the type is defined and contains
at least one public member. Make sure the imported element name doesn't use
any aliases."

I downloaded, unblocked, and installed the Office PIA's, but I still get the
same result. Is this another dirty Vista trick, or have I missed something?

Marty
 
J

Jim Cone

It doesn't work using VBA (XL 2003 - Windows XP) either,
I get "Variable not defined" and it highlights "Microsoft".
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)



"Uncle Martin" <[email protected]>
wrote in message
Hi,
I am trying to learn VSTO programming. I have Windows Vista installed.

When I type Imports Excel = Microsoft.Office.Interop.Excel, Intellisense
does not recognize anything after Microsoft. A green squiggly appears under
the statement. The tool tip says, "Namespace or type specified in the
Imports 'Microsoft.Office.Interop.Excel' doesn't contain any public member or
cannot be found. Make sure the namespace or the type is defined and contains
at least one public member. Make sure the imported element name doesn't use
any aliases."

I downloaded, unblocked, and installed the Office PIA's, but I still get the
same result. Is this another dirty Vista trick, or have I missed something?
Marty
 
U

Uncle Martin

I am "replying" to my own post to supply an addendum:

After playing around a bit, I find that this line of code *does* work when
you are using one of the office templates, e.g., the Excel Workbook Visual
Studio template. However, I was trying to follow an example in the book,
"Visual Studio Tools for Office Using Visual Basic 2005" by Eric Carter and
Eric Lippert. The example involves creating an automation add-in using a
Visual Basic Class Library template. For some reason, in that environment
(on my system), the command is not recognized. Later in the code example,
the following line appears:

Dim r2 As Excel.Range = number2

As you may expect, the compiler balks at that, also.

Is there some reason that you cannot access this namespace from a class
library project? If that is the case, why did the authors include that line
of code in their example? Is it just a typo, or has something changed
because I am using Vista? Did I miss some other setting that must be
included in order to access it?

Thanks,

Marty
 
U

Uncle Martin

Well, I guess I should read more carefully!

The book says, "To use Listing 3.2, you must add a reference to the Excel
11.0 Object Library and also add the code Imports Excel =
Microsoft.Office.Interop.Excel."

I had missed the bit about adding a reference to the Excel 11.0 Object
Library; I only saw "add the code...".

I have added references in VBA, but this was my first time in VSTO, so I had
to go hunting: Under the Project Menu, select Add Reference... Then click on
the COM tab and scroll down.

Well, at least I hope someone else will be able to benefit from my error!

Thanks,

Marty
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top