Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Thread Tools Display Modes
Old 02-05-2009, 04:38 PM
jtrirogoff jtrirogoff is offline
Unable to run the specified macro
Join Date: Feb 2009
Posts: 1
jtrirogoff is on a distinguished road
Default Unable to run the specified macro

Hi there,

I get this error when I try and open a document based on this template (Template_X) through my C# application, but only sometimes... it seems kind of random.

This is my scenario...I have a global template (Template_Y) that I placed in the Word Startup folder so that I can incorporate common macros in all my templates that I create and I have Template_X which contains some custom macros, one of which calls a macro in the global template file. My C# App builds a .doc file by opening Template_X (at this point Template_Y is also linked to this document since it's a global template). Things go wrong when I try and call a macro in Template_Y from my C# App:

WordApp.GetType().InvokeMember("Run", System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod, null, WordApp, new Object[]{"MacroName"});

The following exception gets thrown:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80020003): Unable to run the specified macro

After spending a lot of time trying to debug this error I came across some very interesting results:

On the C# side of things
- It happens randomly... more often then not it fails, but sometimes it works.
- Placing a breakpoint before the call to run the macro seems to solve the problem and my document generates successfully everytime... removing the breakpoint causes the Exception to happen again.

On the Word side of things
- I have many similar templates like Template_X and they have never had a problem. After doing some comparisons and testing I was able to determine that some how the number of ActiveX checkboxes on the template is the cause of the problem. Template_X has 24 checkboxes all my other templates have more or fewer than 24 but Template_X is the only one with 24 checkboxes. Removing one or more, or adding one or more checkboxes to Template_X causes my C# App to generate the document successfully... don't ask me how. Another interesting fact is that if I make it so my other templates contain 24 checkboxes they will also fail when try to generate a document with the same exception as I mentioned above.
- If I bypass the whole global template thing and move all the macros into Template_X, the document generates successfully everytime. This however is not an ideal solution for me as I need to use a global template.

At this point I'm totally lost... Is there a problem with my C# App? Is there some weird bug in Word that I don't know about that makes it freakout when there are X number of ActiveX checkboxes on a template? If anyone has any advice, or has experienced a bug like this I would really appreciate any suggestions on solving this problem. Thx!

BTW I'm using Word 2007 and Visual Studio 2005
Reply With Quote

Thread Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Issue Basanth Excel 1 12-05-2008 08:07 PM
Find and Replace Macro - A Better Way Tribos Word VBA 0 10-08-2008 03:22 AM
Macro Writing cweachter Excel 0 08-09-2008 08:30 PM
Simple macro undoable? garon5 Outlook 0 04-20-2007 10:27 AM
Enable/Disable Macro in Outlook JimDandy Misc 0 05-11-2006 06:17 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:23 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd. is not affiliated with Microsoft