Хочу поделиться радостью. Препарировал буржуйскую надстройку и наконец увидел как это делается. Ключевой фрагмент Application.MacroOptions. Вот код двух процедур:
Sub AddDcfcFunctions()
'
'To be added to User Defined section
'
Dim fNames() As String
Dim fHelpIds() As Integer
'Help file
Dim sHelpFile As String
Dim bGotHelpFileOk As Boolean
bGotHelpFileOk = GetHelpFileLocation(sHelpFile, False)
GetFunctionInfo fNames, fHelpIds
Dim lb, ub
lb = LBound(fHelpIds)
ub = UBound(fHelpIds)
Dim i As Integer
For i = lb To ub
Application.MacroOptions Macro:=fNames(i, 0), _
Description:=fNames(i, 1), _
HelpContextID:=fHelpIds(i), HelpFile:=sHelpFile, _
Category:=14
Next i
'Application.MacroOptions Macro:="SuperFit", _
' Description:="Sums or counts cells based on a specified fill color", _
' HelpContextID:=1100, HelpFile:="c:\tmploc\dcfc_help.chm", _
' Category:=14
End Sub
Sub GetFunctionInfo(f() As String, ID() As Integer)
'Fills f with 0 to n-1, 0 to 1 and helpIds with 0 to n-1
'
Dim n As Integer
n = 9
ReDim f(0 To n - 1, 0 To 1) As String
ReDim ID(0 To n - 1) As Integer
'Linear Interp
f(0, 0) = "LinearInterp"
f(0, 1) = "Given a source data set (X, Y values), uses linear interpolation " & _
"to calculate corresponding output values for one or more input values"
ID(0) = 1100
'Spline
f(1, 0) = "CubicSpline"
f(1, 1) = "Given a source data set (X, Y values), uses cubic spline interpolation " & _
"to calculate corresponding output values for one or more input values"
ID(1) = 1200
'FlexSpline
f(2, 0) = "FlexSpline"
f(2, 1) = "Fits a 'Flexible Spline' curve to a set of source data points, and " & _
"then evaluates one or more X values based on the curve. The shape of the spline can be" & _
" controlled by setting the curve slopes at any source point."
ID(2) = 1300
'Polynomial
f(3, 0) = "PolyFit"
f(3, 1) = "Fits a polynomial curve of specified order to a set of source data points, and " & _
"then evaluates one or more X values based on the curve. Options: weight values of " & _
"data points, equation constant"
ID(3) = 1400
'PolyCoef"
f(4, 0) = "PolyCoef"
f(4, 1) = "Fits a polynomial curve of specified order to a source dataset, and " & _
"then returns the Polynomial coefficients. Options: weight values of " & _
"data points, equation constant"
ID(4) = 1500
'RegionFit"
f(5, 0) = "RegionFit"
f(5, 1) = "Using the dataset points in the surrounding region, fits a polynomial curve " & _
"calculate an estimate for each given New_X value. Options " & _
"include: fit order, weight values, data subset size, equation const."
ID(5) = 1600
'MovingAvg"
f(6, 0) = "MovingAvg"
f(6, 1) = "Performs a moving average filter on a set of data (smooths data). Returns an array " & _
"of averaged points as output - (1) highlight cells where output will be " & _
"(2) enter equation (3) press " & _
"ctl-shift-enter to receive all output points"
ID(6) = 1700
'MedianFit"
f(7, 0) = "MedianFilter"
f(7, 1) = "Performs a median filter on a set of data (reduces noise in data). Returns an array " & _
"of points as output - (1) highlight cells where output will be " & _
"(2) enter equation (3) press " & _
"ctl-shift-enter to receive all output points"
ID(7) = 1800
'gaussianSmooth"
f(8, 0) = "GaussianSmooth"
f(8, 1) = "Performs a gaussian smoothing filter on a set of data. Returns an array " & _
"of smoothed points as output - (1) highlight cells where output will be " & _
"(2) enter equation (3) press " & _
"ctl-shift-enter to receive all output points"
ID(8) = 1900
End Sub
Великолепно, теперь мы умеем красиво оформлять наши пользовательские функции. Ура.
Sub AddDcfcFunctions()
'
'To be added to User Defined section
'
Dim fNames() As String
Dim fHelpIds() As Integer
'Help file
Dim sHelpFile As String
Dim bGotHelpFileOk As Boolean
bGotHelpFileOk = GetHelpFileLocation(sHelpFile, False)
GetFunctionInfo fNames, fHelpIds
Dim lb, ub
lb = LBound(fHelpIds)
ub = UBound(fHelpIds)
Dim i As Integer
For i = lb To ub
Application.MacroOptions Macro:=fNames(i, 0), _
Description:=fNames(i, 1), _
HelpContextID:=fHelpIds(i), HelpFile:=sHelpFile, _
Category:=14
Next i
'Application.MacroOptions Macro:="SuperFit", _
' Description:="Sums or counts cells based on a specified fill color", _
' HelpContextID:=1100, HelpFile:="c:\tmploc\dcfc_help.chm", _
' Category:=14
End Sub
Sub GetFunctionInfo(f() As String, ID() As Integer)
'Fills f with 0 to n-1, 0 to 1 and helpIds with 0 to n-1
'
Dim n As Integer
n = 9
ReDim f(0 To n - 1, 0 To 1) As String
ReDim ID(0 To n - 1) As Integer
'Linear Interp
f(0, 0) = "LinearInterp"
f(0, 1) = "Given a source data set (X, Y values), uses linear interpolation " & _
"to calculate corresponding output values for one or more input values"
ID(0) = 1100
'Spline
f(1, 0) = "CubicSpline"
f(1, 1) = "Given a source data set (X, Y values), uses cubic spline interpolation " & _
"to calculate corresponding output values for one or more input values"
ID(1) = 1200
'FlexSpline
f(2, 0) = "FlexSpline"
f(2, 1) = "Fits a 'Flexible Spline' curve to a set of source data points, and " & _
"then evaluates one or more X values based on the curve. The shape of the spline can be" & _
" controlled by setting the curve slopes at any source point."
ID(2) = 1300
'Polynomial
f(3, 0) = "PolyFit"
f(3, 1) = "Fits a polynomial curve of specified order to a set of source data points, and " & _
"then evaluates one or more X values based on the curve. Options: weight values of " & _
"data points, equation constant"
ID(3) = 1400
'PolyCoef"
f(4, 0) = "PolyCoef"
f(4, 1) = "Fits a polynomial curve of specified order to a source dataset, and " & _
"then returns the Polynomial coefficients. Options: weight values of " & _
"data points, equation constant"
ID(4) = 1500
'RegionFit"
f(5, 0) = "RegionFit"
f(5, 1) = "Using the dataset points in the surrounding region, fits a polynomial curve " & _
"calculate an estimate for each given New_X value. Options " & _
"include: fit order, weight values, data subset size, equation const."
ID(5) = 1600
'MovingAvg"
f(6, 0) = "MovingAvg"
f(6, 1) = "Performs a moving average filter on a set of data (smooths data). Returns an array " & _
"of averaged points as output - (1) highlight cells where output will be " & _
"(2) enter equation (3) press " & _
"ctl-shift-enter to receive all output points"
ID(6) = 1700
'MedianFit"
f(7, 0) = "MedianFilter"
f(7, 1) = "Performs a median filter on a set of data (reduces noise in data). Returns an array " & _
"of points as output - (1) highlight cells where output will be " & _
"(2) enter equation (3) press " & _
"ctl-shift-enter to receive all output points"
ID(7) = 1800
'gaussianSmooth"
f(8, 0) = "GaussianSmooth"
f(8, 1) = "Performs a gaussian smoothing filter on a set of data. Returns an array " & _
"of smoothed points as output - (1) highlight cells where output will be " & _
"(2) enter equation (3) press " & _
"ctl-shift-enter to receive all output points"
ID(8) = 1900
End Sub
Великолепно, теперь мы умеем красиво оформлять наши пользовательские функции. Ура.