LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Adding MAcros using C#

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_Componen tType.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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding strings using macros ultrarev Excel Worksheet Functions 5 December 19th 08 09:32 PM
Adding macros to toolbars Elsa Excel Discussion (Misc queries) 1 January 30th 07 09:38 PM
ex.=($B$4+C4) in macros for row why adding rest Sherry Excel Worksheet Functions 4 December 30th 05 12:19 AM
ex.=($B$4+C4) in macros for row why adding rest Sherry Excel Worksheet Functions 0 December 29th 05 06:29 PM
Adding buttons with macros Shatin Excel Programming 0 January 28th 04 04:40 AM


All times are GMT +1. The time now is 02:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"