I can call a macro from within my add-in with the following code:
Application.Run(MACRO_NAME);
Where Application
is an instance of Microsoft.Office.Interop.Excel.Application
. I would like to be able to check to see if the macro exists (and if I have perm开发者_JAVA百科ission to run it) before making the call to Run()
. Right now I am simply putting the call in a try
block but I hate to use exception handling for program control.
Is there a way to see what macros are available to run?
You could always check for a specific module by looking into this.Application.VBProject.VBComponents (search by VBIDE.VBComponent.Name)
You can also search for a string in a VBComponent's code, to make sure it's there. Not much more you can do.
Howewer, a try-catch is a perfectly fine approach. So many things could go bad that you would need exception handling anyway. I would stick to it.
精彩评论