开发者

How can I check for a macro's existence/permission from my add-in?

开发者 https://www.devze.com 2023-02-12 01:06 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消