gpt4 book ai didi

vba - 如何在宏中实现文档?

转载 作者:行者123 更新时间:2023-12-04 21:37:25 24 4
gpt4 key购买 nike

如何在宏中实现文档?
我为我的 excel 工作表编写了一个自定义函数。但是我不知道如何实现文档,这样如果在功能栏中键入函数,就会像 excel 中的标准函数一样显示解释。

是否可以实现该文档?

代码:

Sub Macro1()
'
' Macro1 Macro
'
End Sub

Function AFRONDENONZEKERHEID(n As Double, decimalePlaatsen As Integer, Optional toggle As Boolean = False)
If n = 0 Then
Exit Function
End If

If toggle Then
AFRONDENONZEKERHEID = Application.WorksheetFunction.Round(n, decimalePlaatsen)
Exit Function
End If

Dim afgerond As Double
Dim procentueleAfnamen As Double

afgerond = Application.WorksheetFunction.Round(n, decimalePlaatsen)
procentueleAfnamen = (afgerond - n) / n * 100


If procentueleAfnamen <= -5 Then
AFRONDENONZEKERHEID = Application.WorksheetFunction.RoundUp(n, decimalePlaatsen)
Else
AFRONDENONZEKERHEID = afgerond
End If

End Function

(对不起荷兰变量)

最佳答案

Is it possible to implement that documentation?



答案是肯定的。

您可以运行例程来注册您的函数。该例程将使用 Macro.Options method .

以下示例说明如何 register a UDF来自约翰·沃肯巴赫:

Here's a simple (but very useful) user-defined function:


Function EXTRACTELEMENT(Txt, n, Separator) As String
EXTRACTELEMENT = Split(Application.Trim(Txt), Separator)(n - 1)
End Function

Here's a VBA macro that provides a description for the EXTRACTELEMENT function, assigns it to a function category, and provides a description for each of its three arguments:


Sub DescribeFunction()
Dim FuncName As String
Dim FuncDesc As String
Dim Category As String
Dim ArgDesc(1 To 3) As String

FuncName = "EXTRACTELEMENT"
FuncDesc = "Returns the nth element of a string that uses a separator character"
Category = 7 'Text category
ArgDesc(1) = "String that contains the elements"
ArgDesc(2) = "Element number to return"
ArgDesc(3) = "Single-character element separator"

Application.MacroOptions _
Macro:=FuncName, _
Description:=FuncDesc, _
Category:=Category, _
ArgumentDescriptions:=ArgDesc
End Sub

关于vba - 如何在宏中实现文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32539909/

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