COMexception error?what should I do...
COMexception error?what should I do...
COMexception error?what should I do...
COMexception error?what should I do...
COMexception error?what should I do...
COMexception error?what should I do... COMexception error?what should I do... COMexception error?what should I do... COMexception error?what should I do... COMexception error?what should I do... COMexception error?what should I do... COMexception error?what should I do... COMexception error?what should I do...
COMexception error?what should I do... COMexception error?what should I do...
COMexception error?what should I do...
Go Back  Xtreme Visual Basic Talk > > > COMexception error?what should I do...


Reply
 
Thread Tools Display Modes
  #1  
Old 05-07-2010, 07:51 PM
bluecandy bluecandy is offline
Newcomer
 
Join Date: May 2010
Location: China
Posts: 11
Question COMexception error?what should I do...


Hi,Mike.I read your tutorial <Automating Office Programs with VB.NET> and wrote program as you write,but I don't know why errors occured.I want to solve it but I don't know what I should do...The code like below:

'had added a reference to the Microsoft Excel Object Library
Imports Excel = Microsoft.Office.Interop.Excel----->error:name conflict

Private OperateExcel()
Dim oApp As Excel.Application
Dim oWB As Excel.Workbook
Dim oWS As Excel.Worksheet
Dim oRange As Excel.Range

oApp = new Excel.Application----->error:Excel is interface,could not "new"

oApp = CreateObject("excel.application") ----->use this code could open excel file
oWB = oApp.Workbooks.open("D:\abc.xls")
oApp.Visible = True
oWS = CType(oWB.Sheets(1), Excel.Worksheet)----->error:COMEXCEPTION error.I watched "oWS"'s value,it was "nothing".How I could solve it ...


I use VS 2008 and OFFICE 2007.There are some worksheets in the excel file opened,and they own their name.
Please help and give me sugestion!Thanks a lot!
Reply With Quote
  #2  
Old 05-08-2010, 10:32 AM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Hi BlueCandy,

Welcome to the forum.

I think that your problems stem from this:

Quote:
Originally Posted by bluecandy View Post
'had added a reference to the Microsoft Excel Object Library
Imports Excel = Microsoft.Office.Interop.Excel----->error:name conflict
My guess is that when your Excel application got installed, the primary interop assemblies (PIAs) were not installed with it. The result is that when you added a reference to the Excel object model, Visual Studio created a local interop assembly for you on the fly. When Visual Studio does this, the reference is already named 'Excel' for you, so you do not need to explicitly declare the alias.

Therefore, I would simply remove the Imports Excel = Microsoft.Office.Interop.Excel statement, and a lot of your problems will go away, and hopefully all of them.

Make this change, let us know how it goes, and post back if there are still problems after you do this...

Hope this helps!
Mike
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
  #3  
Old 05-08-2010, 07:32 PM
bluecandy bluecandy is offline
Newcomer
 
Join Date: May 2010
Location: China
Posts: 11
Default

Hi,Mike,thanks for your welcoming!I removed the "Imports Excel = ....", I used "Imports Microsoft.Offcie.Interop.Excel",now it could open a excel file .But there is new problem :
oWS= oWB.Worksheet(1)
---->VS told me :system.runtime.interop services.COMException(0x80020003):member not found

I don't know why it happened...could you give me more suggestion?
THX!
Reply With Quote
  #4  
Old 05-08-2010, 07:46 PM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Hmmm... I think you'll need to do two things for me to be able to help you out:

(1) Could you list all the references that you are using?

(2) Show more of your code. In particular, show the code leading up to the line oWS = oWB.Worksheet(1) that is giving you trouble.

If you provide us this info, we should be able to help you through it...

- Mie
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
  #5  
Old 05-08-2010, 10:07 PM
bluecandy bluecandy is offline
Newcomer
 
Join Date: May 2010
Location: China
Posts: 11
Default

Hi,Mike!I'm so happy that all problems were solved.Thanks for your suggestion!
When I read your first reply,I thought about it and found that maybe I'd done something before "imports excel" but I'd forgotten it...Em...I'm so embarrassed now
I created a new .net application ,"imports excel = microsoft.office.interop.excel" could use in it ,then every problem was disappeared...

Well,I'm sorry and I hope this didn't interrupt you...
Reply With Quote
  #6  
Old 05-09-2010, 06:00 AM
Mike Rosenblum's Avatar
Mike Rosenblum Mike Rosenblum is offline
Microsoft Excel MVP

Forum Leader
* Guru *
 
Join Date: Jul 2003
Location: New York, NY, USA
Posts: 7,848
Default

Cool, no problem!

Very glad you got it.
__________________
My Articles:
| Excel from .NET | Excel RibbonX using VBA | Excel from VB6 | CVErr in .NET | MVP |
Avatar by Lebb
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
COMexception error?what should I do...
COMexception error?what should I do...
COMexception error?what should I do... COMexception error?what should I do...
COMexception error?what should I do...
COMexception error?what should I do...
COMexception error?what should I do... COMexception error?what should I do... COMexception error?what should I do... COMexception error?what should I do... COMexception error?what should I do... COMexception error?what should I do... COMexception error?what should I do...
COMexception error?what should I do...
COMexception error?what should I do...
 
COMexception error?what should I do...
COMexception error?what should I do...
 
-->