Unable to run the specified macro

J

jtrirogoff

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top