M
Michael Wu
I wonder if anyone can shed some light on how to automate Excel from a C#
program.
What I like to do is this,
1) Find if an Excel spreadsheet is alreay opened (identify the Excel file
path)
2) if that particular Excel is alreay launch, get the Excel Object
3) run a macro on the Excel Object
I made some progress using
tlbimp on Excel.exe to get the interop lib
Excel._Application excelApp = (Excel._Application)
System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
to get an Excel object. But this method, does not allow me to get a
particular Excel object. If I have more than one Excel session open, I think
I always got the one opened most recently. I thne tried the win32
GetObject(string, string), but this one alway generate a runtime error
System.InteropServices.MarshalDirectiveException : PInvoke restriction: can
not return variants.
Any help will be greatly appreciated.
Regards
Michael
program.
What I like to do is this,
1) Find if an Excel spreadsheet is alreay opened (identify the Excel file
path)
2) if that particular Excel is alreay launch, get the Excel Object
3) run a macro on the Excel Object
I made some progress using
tlbimp on Excel.exe to get the interop lib
Excel._Application excelApp = (Excel._Application)
System.Runtime.InteropServices.Marshal.GetActiveObject("Excel.Application");
to get an Excel object. But this method, does not allow me to get a
particular Excel object. If I have more than one Excel session open, I think
I always got the one opened most recently. I thne tried the win32
GetObject(string, string), but this one alway generate a runtime error
System.InteropServices.MarshalDirectiveException : PInvoke restriction: can
not return variants.
Any help will be greatly appreciated.
Regards
Michael