I am having an exception while addding an Excel Macro using C#. I use
the following code to add a macro.

1. Excel.Application xl = null;
2. Excel._Workbook wb = null;
3. Excel._Worksheet sheet = null;
4. VBIDE.VBComponent module = null;
5. string Macro = "assing a macro"; //to be done
6. xl = new Excel.Application();
7. xl.Visible = false;

8. wb = (Excel._Workbook)(xl.Workbooks.Add( Missing.Value ));
9. sheet = (Excel._Worksheet)wb.ActiveSheet;
10. module = wb.VBProject.VBComponents.Add
(VBIDE.vbext_ComponentType.vbext_ct_StdModule);
11. module.CodeModule.AddFromString(Macro);

Line number throws an exception of type
System.Runtime.InteropServices.COMException with the message:
Exception from HRESULT: 0x800A03EC

Can someone give an idea what I am doing wrong here.

--~--~---------~--~----~------------~-------~--~----~
Visit the blog to download Excel tutorials at 
http://www.excel-macros.blogspot.com

To post to this group, send email to excel-macros@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/excel-macros?hl=en

Visit & Join Our Orkut Community at 
http://www.orkut.com/Community.aspx?cmm=22913620

Visit the blog to download Excel tutorials at 
http://www.excel-macros.blogspot.com

To Learn VBA Macros Please visit http://www.vbamacros.blogspot.com

To see the Daily Excel Tips, Go to:
http://exceldailytip.blogspot.com
-~----------~----~----~----~------~----~------~--~---

Reply via email to