使用excel插件注册UDF和参数的描述

我有一个UDF的getRegExResult插件。 我想为这个函数添加一个函数描述和参数描述,所以当用户安装插件时,closures,打开excel几次,进入“插入函数”对话框,他将能够find具有参数描述的函数。

这里也是一样的问题。 我find了一个适合我需求的答案 。 除…

我希望能够通过Excel Addin来做到这一点。 我的想法是把调用插入到workbook_open事件像这样:

 Private Sub Workbook_Open() Call getRegExResultRegister End Sub Public Sub getRegExResultRegister() Application.MacroOptions Macro:="getRegExResult", Description:="Returns a concatenated string of NONE, ONE, or ALL Regular Expression Match(es).", Category:="User Defined", _ ArgumentDescriptions:=Array("Source string to inspect for matches.", _ "Regular Expression Pattern. Eg ""\d+"" matches at least 1 or more digits.", _ "[Default = True] True = Returns all the matches found. False = Returns only the first match.", _ "[Default = True] True = Not case sensitive search. False = Case sensitive search.", _ "[Default = "";""] Delimiter to insert between every macth, if more than 1 matches are found.") End Sub 

我安装插件后,closures,打开excel,我得到运行时错误1004:“不能编辑一个隐藏的工作簿上的macrosUhnide工作簿…”

问题1

如何取消隐藏插件工作簿? 我尝试在调用注册之前将Thisworkbook.Windows(1).visible = True放入Workbook_open事件中,但导致Runtime 9下标超出范围。

问题2

如果隐藏插件是不可能的,有没有其他的方法来做到这一点?


感谢帮助。

类似的问题:
Excel在Personal.xslb中注册UDF

编辑#1

目前的代码做我想要的,只有一个错误。 当我打开一些现有的工作簿,我得到2个Excel窗口。 其中一个打开的工作簿(正确),其中一个插件(不需要)。 如何摆脱第二个窗口?

 Private Sub Workbook_Open() With ThisWorkbook .IsAddin = False Call getRegExResultRegister .IsAddin = True .Saved = True End With End Sub 

设置.MacroOption之前,请使用以下代码:

 Application.AddIns("Your Addin name").Installed = True 

此代码可能需要在之前:

 Application.AddIns("Your Addin name").Installed = False 

根据MSDN博客 ,这是因为自动加载的AddIns在启动时并不真正打开。 所以你必须在重新打开它之前closures它。

请注意, "Your Addin name"不是AddIn的文件名,而是其名称,因为它出现在加载项选项窗口中。

编辑:完整的代码,不要忘记编辑AddIn名称

 Public Sub getRegExResultRegister() Application.AddIns("Your Addin name").Installed = False Application.AddIns("Your Addin name").Installed = True Application.MacroOptions Macro:="getRegExResult", Description:="Returns a concatenated string of NONE, ONE, or ALL Regular Expression Match(es).", Category:="User Defined", _ ArgumentDescriptions:=Array("Source string to inspect for matches.", _ "Regular Expression Pattern. Eg ""\d+"" matches at least 1 or more digits.", _ "[Default = True] True = Returns all the matches found. False = Returns only the first match.", _ "[Default = True] True = Not case sensitive search. False = Case sensitive search.", _ "[Default = "";""] Delimiter to insert between every macth, if more than 1 matches are found.") End Sub