gpt4 book ai didi

vba - 使用 excel 插件注册带有参数描述的 UDF

转载 作者:行者123 更新时间:2023-12-02 11:52:45 25 4
gpt4 key购买 nike

我有一个带有 UDF getRegExResult 的插件。我想向该函数添加函数描述和参数描述,因此当用户安装插件、关闭、打开 Excel 几次并进入“插入函数”对话框时,他将能够找到带有参数描述的函数。

同样的问题here 。我找到了一个answer这适合我的需要。除了...

我希望能够通过 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. E.g. ""\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

安装插件后,关闭并打开 Excel,出现运行时错误 1004:“无法编辑隐藏工作簿上的宏。Uhnide 工作簿...”

问题 1

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

问题 2

如果无法取消隐藏插件,还有其他方法吗?

<小时/>

感谢您的帮助。

类似问题:
Excel Register UDF in Personal.xslb

编辑#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 Blog ,这是因为自动加载的 AddIns 在启动时并未真正打开。因此,您必须先关闭它,然后才能重新打开它。

请注意,“您的外接程序名称” 不是外接程序的文件名,而是其在外接程序选项窗口中显示的名称。

编辑:完整代码,不要忘记编辑插件名称

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. E.g. ""\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

关于vba - 使用 excel 插件注册带有参数描述的 UDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41465478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com