I have also followed up your late binding code , its great because
earlier I was creating the ApplicationClass instance
but with this code I get the following exception at the add line
I am using Excel instead of Word
the code is
Type t = Type.GetTypeFromProgID( "Excel.Application" );
object w = Activator.CreateInstance( t );
// Visible True
t.InvokeMember( "Visible", BindingFlags.SetProperty,null, w, new
Object[] { true } );
// w WorkBooks
object docs = t.InvokeMember( "WorkBooks",
BindingFlags.GetProperty,null, w, null );
// w Add method
t.InvokeMember( "Add", BindingFlags.InvokeMethod,null, docs, null );
w = null;
the exception is
"System.Reflection.TargetException: Object does not match target
type.\r\n at System.RuntimeType.InvokeDispMethod(String name,
BindingFlags invokeAttr, Object target, Object[] args, Boolean[]
byrefModifiers, Int32 culture, String[] namedParameters)\r\n at
System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr,
Binder binder, Object target, Object[] args, ParameterModifier[]
modifiers, CultureInfo culture, String[] namedParameters)\r\n at
System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder
binder, Object target, Object[] args)\r\n at
ExcelTry2.ExcelInterOp.Init() in c:\\documents and settings\\champ\\my
documents\\visual studio
projects\\exceltry2\\exceltry2\\excelinterop.cs:li ne 41"
"Dent" <dt******@hotmail.com> wrote in message news:<uh**************@TK2MSFTNGP12.phx.gbl>...
Wiktor,
if you use Excel.Application in your .NET code, you assume to have a
COMInterop assembly generated from Excel type library. just look for it in
the /debug or /release folder and distribute it with your application.
that way the early binding will work.
I was not able to get my early-binding code to work. In short, here is the
code:
c#
using Microsoft.Office.Interop.Excel;
using excel = Microsoft.Office.Interop.Excel;
class GetInventory
{
public static void Main()
{
try
{
excel.Application ExcelObj = new excel.Application();
... (working with ExcelObj)
System.Runtime.InteropServices.Marshal.ReleaseComO bject(ExcelObj);
ExcelObj = null;
}
catch(IOException e) //not sure about this catch statement. I need
to study my exception handling.
{
...
}
This is the code that generated the "System.IO.FileNotFoundException" that I
wrote about in my first posting. I looked for the COMInterop assembly in
the locations you suggested, but I didn't find anything. Do I need to use a
specific compiler switch to generate this assembly? I compiled with the
"Build" on the toolbar of Visual Studio 2003. What kind of file extension
am I looking for on that COMInterop assembly?
I tried installing the PIAs for XP on the 2000 machine, but this was a
mistake. I also tried copying Interop.excel.dll and
microsoft.office.interop.excel.dll to that machine and registering them with
regsvr32. This was also an obvious mistake because on both attempts to
register, I got the error
".dll was loaded, but the DLLRegServer entry point was not found.
DllRegisterServer may not be exported, or a corrupt version of
interop.excel.dll may be in memory. Consider using pview to detect and
remove it."
It was a shot in the dark on my part.
if you wish to use late binding, you do not have to use
Excel.Application object. in fact, you should not use it at all! instead,
create a type that correspond to it, create object of the type and invoke
its metods/properties. it is much easier to work with late binding with
VB.NET, though, because vb.net supports late binding at language level.
With regards to the late binding example, thank you. It works just as you
said. I had tried a couple of other examples, but they didn't work. From
your example, I expect to be able to build something useful.
Thank you,
Dennis