.net excel automation

My goal is   - in a .net project(vs2005, vb.net, [windows form application] project,office2007 or office 2003)-    to  open an excel file , write in it and close it .
In the project i referenced to com assembly which is [ excel object library 11.0]

here is the simple code i am trying to run.

dim app   as Excel.Application = new Excel.Application
dim wb  as Workbook =app.Workbooks.open("c:\a.xls")
dim sheet  as Excel.Worksheet =wb.Sheets("Sheet1")
dim range as Excel.Range= sheet.Range("A1")

when i execute this code,at the last line of the code, crushes with exception:


Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Excel.Range'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00020846-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

Could you help me about it, thanks already





karynchAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodeCruiserCommented:
Did you download, install and reference the Office PIA?
0
CodeCruiserCommented:
0
NorieVBA ExpertCommented:
Works fine for me if I add Excel in front of Workbook.

dim wb  as Excel.Workbook =app.Workbooks.open("c:\a.xls")
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

karynchAuthor Commented:
i installed pia, i didnot changed referenced assemblies( please tell me if i have to do something different to reference these  freshly installed PIA ); so it is still COM assembly which is excel object library 11.

well, it did not changed situation, still getting same error.

imnorie,
up there i forgot add Excel  namespace, but in the actual code, it is like Excel.Workbook.

one more thing:
if i do something like :

wb.Sheets("Sheet1").Range("A1")="Hello"

it does the job-getting no error;
 but while coding, when you put period after  
wb.Sheets("Sheet1")
intellisense does not bring the members of Range.

( compiler does  the cast operation dynamically i think.)









0
CodeCruiserCommented:
Remove the old reference and add it again from .NET tab.
0
karynchAuthor Commented:

i did it as you say, result is same,
i sent the image of assembly.
 referenced assembly
0
karynchAuthor Commented:
after installation of  pro office  plus 2010, problem 's gone.
thank you
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
karynchAuthor Commented:
error disappeared
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.