.NET / Excel automation - MissingMethodException: Method not found

B

Benjamin

I am making a Windows EXE (.NET Visual Basic Windows Application).
I would like to make it possible to open Excel Worksheets from my EXE.
This should work independent of Excel version on client machine (it is out
of my control to know what versions of Excel different users has.)
Anyway let us say that Excel 2000 is the oldest acceptable version.
I build the EXE on a PC with Excel 2000. But I it is not working on an Excel
2003 machine!

On my development machine I have "Microsoft Excel 2000 (9.0.6926 SP-3)".
when I do "Add Reference"/"COM", in Visual Studio, a reference is done to
"Microsoft Excel 9.0 Object Library".
When I run the executable on this machine it works perfectly.

But when I try to run it on another development machine with "Microsoft
Office Excel 2003 (11.6355.6360) SP1" i get error message:

System.MissingMethodException: Method not found: Excel.Workbook
Excel.Workbooks.Open(System.String, System.Object, System.Object,
System.Object, System.Object, System.Object, System.Object, System.Object,
System.Object, System.Object, System.Object, System.Object, System.Object).

Following information is not a part of the problem description, but anyway...
IF I instead build the solution on my "Excel 2003"-development machine, then
of course excel automation is working on this machine.
A reference to "Microsoft Excel 11.0 Object Library", is then done.

Any hint is appreciated!

Best regards,
Benjamin
 
P

Peter Huang [MSFT]

Hi

To access COM object(office product) from .NET, we need an interop assembly.
e.g.
Interop.Excel.dll
Interop.Office.dll
Interop.VBIDE.dll

For office XP and 2003 we have official PIA, and they are not compatible
with each other. For earlier version(before office 2000 including office
2000, we have no official PIA)
Office Primary Interop Assemblies
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/h
tml/wrrefofficeprimaryinteropassemblies.asp

Primary Interop Assemblies
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconPrimaryInteropAssemblies.asp

Working with the Office XP Primary Interop Assemblies
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnoxpta/htm
l/odc_oxppias.asp

So it would better to build a standalone build for each version if you want
to use early binding.

e.g
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim exApp As New Excel.Application
exApp.Visible = True
exApp.Workbooks.Add()
Dim ws As Excel.Worksheet = exApp.ActiveSheet
ws.Range("A1").Value = "Hello"
End Sub


Or we can use late-binding, in which we did not need to add reference to
the Excel library and the interop assembly is not needed.
e.g.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim exApp As Object
exApp = CreateObject("Excel.Application")
exApp.Visible = True
exApp.Workbooks.Add()
Dim ws As Object = exApp.ActiveSheet
ws.Range("A1").Value = "Hello"
End Sub

Hope this helps.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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