Replace these statements in your code
from
// Create an instance of Excel.
oExcel = new Excel.Application();
// Add a workbook.
oBook = oExcel.Workbooks.Add(oMissing);
to
oExcel = new Excel.Application();
oBook = oExcel.Workbooks.open("C:\temp\book1.xls);
I assume you are creating an Excel Application and then opening a workbook.
If you are just adding code to the opened workbook then use this
oBook = Thisworkbook
If you are working in a macro and not C# you need to put a "SET" in front of
each command.
"Aerojade" wrote:
I have found references and code on the net which helps me add code in the
form of an Excel Macro. However it shows how to create a new module and then
add functions to it. How to add functions to the thisWorkbook part of the
File.
the link that shows how to programatically add macro o a new module is:
http://support.microsoft.com/kb/303872
i dont want to add it to a new module but to "ThisWorkbook"
Please help