PC Review


Reply
Thread Tools Rate Thread

Adding MAcros using C#

 
 
shree
Guest
Posts: n/a
 
      18th Nov 2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Macros to Toolbar jokelly27 Microsoft Word New Users 5 25th Sep 2009 02:58 PM
Adding macros to toolbars =?Utf-8?B?RWxzYQ==?= Microsoft Excel Misc 1 30th Jan 2007 09:38 PM
ex.=($B$4+C4) in macros for row why adding rest =?Utf-8?B?U2hlcnJ5?= Microsoft Excel Worksheet Functions 4 30th Dec 2005 12:19 AM
Excel/automation Gurus., please help... extract macros from excel and adding new macros into an excel sheet. OhMyGaw Microsoft C# .NET 3 10th Aug 2005 01:52 AM
Adding buttons with macros mike Microsoft Excel Programming 5 28th Jan 2004 04:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:45 AM.