3

I am running a console application in MS Visual Studio 2010 in Windows 7 and I get the following error message when trying to create a new Excel application using a standard C# command:

enter image description here

The full code is as follows and the error occurs when executing new Excel.Application() command:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Excel = Microsoft.Office.Interop.Excel;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            // Open a Excel spreadsheet
            Excel.Application excel = new Excel.Application();
        }
    }
}

I have made sure the appropriate .NET reference has been added to the project:

enter image description here

I am a little puzzled as to what else I should be doing next. I have seen one or two other posts that mention similar looking error messages, but I am still none the wiser on how to proceed.

I have the trial version and "Starter" version of Microsoft Office 2010 installed only, so would this make any difference? Do I need to purchase the full-on Office before I can attempt anything like this?

1
  • 1
    I would say that the trial version could be the issue yes, AFAIK you need to have full versions installed of the Office products if you are doing automation. More so, considering how simple your code is. (I could be wrong though) Commented Oct 25, 2011 at 13:35

2 Answers 2

3

It's not the fact that it's a starter or trial version, I suspect. Read a bit down the thread in the second link that KreepN posted and you'll find this:

"I found the problem for me with the exact same error that you are getting was that I installed Office from the download using the "Click to run"."

MS pushes you into the click to run (CTR) edition of office when you download a trial or buy on line. For purposes of external automation, CTR is utterly useless. It installs and runs in a kind of VM that's only alive when you've launched one of the Office apps and is unaware of and inaccessible to what's happening on the physical computer it's running on.

As a test, check to see if you have any mysterious additional drives (typically, a Q: drive). That's another symptom that your computer has been "blessed" (some might say "infested") by CTR.

Sign up to request clarification or add additional context in comments.

Comments

2

The trial version is not enough to support the COM interop. I did a little bit of searching and found someone else having the same problem.

He obviously doesn't have it installed, and since he is dropping the same error as you, I'd bet that you need a full version for it to register the interoperability with your system.

EDIT :

Did some more digging and found this SO user with the same problem a while back as well. It seems our solution still holds :).

2 Comments

Thanks. Will any version of Office do?
Yes, although I think 2007 will get you version 12 of the interop and 2010 will get you 14. They have slight feature changes so it won't matter too much, but I've seen people that absolutely need certain features sometimes so it's really up to you :).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.