S
shree
I am having an exception while adding 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 10 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.
thanks,
Shrish
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 10 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.
thanks,
Shrish