사용자 정의 함수에 도구 설명을 추가하는 방법
Excel 2007에서 사용자 정의 함수에 설명 및 매개 변수 힌트를 추가하려면 어떻게합니까? 기본 제공 함수에 대한 함수 호출을 입력하기 시작하면 Excel에 설명 및 매개 변수 목록 (도구 설명)이 표시됩니다. 내가 정의한 함수에 대해서도 똑같이하고 싶습니다.
수식 삽입 마법사뿐만 아니라 수식 상자 "=myFun("
에를 입력 "("
하면 도구 설명이 다음과 같이 표시됩니다."=average("
VBA 도움말에는 도움이없고 MSDN에는없고 내가 찾을 수있는 Excel 및 VBA 전용 포럼에는 전혀 도움이되지 않으므로 이것은 분명히 긴 기회입니다.
Stephen Bullen의 Professional Excel Development에서는 UDF를 등록하는 방법에 대해 설명합니다.이를 통해 함수 인수 대화 상자에 설명을 표시 할 수 있습니다.
Function IFERROR(ByRef ToEvaluate As Variant, ByRef Default As Variant) As Variant
If IsError(ToEvaluate) Then
IFERROR = Default
Else
IFERROR = ToEvaluate
End If
End Function
Sub RegisterUDF()
Dim s As String
s = "Provides a shortcut replacement for the common worksheet construct" & vbLf _
& "IF(ISERROR(<expression>, <default>, <expression>)"
Application.MacroOptions macro:="IFERROR", Description:=s, Category:=9
End Sub
Sub UnregisterUDF()
Application.MacroOptions Macro:="IFERROR", Description:=Empty, Category:=Empty
End Sub
출처 : http://www.ozgrid.com/forum/showthread.php?t=78123&page=1
함수 인수 대화 상자를 표시하려면 함수 이름을 입력하고를 누릅니다 CtrlA. 또는 수식 입력 줄에서 "fx"기호를 클릭합니다.
툴팁 솔루션은 아니지만 적절한 해결 방법 :
UDF 입력을 =MyUDF(
시작한 다음 CTRL+ Shift+ 를 누르면 A기능 매개 변수가 표시됩니다. 이러한 매개 변수에 의미있는 이름이있는 한 최소한 실행 가능한 프롬프트가 있습니다.
예를 들면 다음과 같습니다.
=MyUDF(
+ CTRL+ Shift+A
다음과 같이 바뀝니다.
=MyUDF(sPath, sFileName)
함수의 "도움말"버전을 생성합니다. 자동 완성 기능의 바로 아래에 표시됩니다. 사용자는 지침을 위해 인접한 셀에서 대신 선택할 수 있습니다.
Public Function Foo(param1 as range, param2 as string) As String
Foo = "Hello world"
End Function
Public Function Foo_Help() as String
Foo_Help = "The Foo function was designed to return the Foo value for a specified range a cells given a specified constant." & CHR(10) & "Parameters:" & CHR(10)
& " param1 as Range : Specifies the range of cells the Foo function should operate on." & CHR(10)
&" param2 as String : Specifies the constant the function should use to calculate Foo"
&" contact the Foo master at master@foo.com for more information."
END FUNCTION
캐리지 리턴은 자동 줄 바꿈을 사용하여 가독성을 향상시킵니다. 하나의 돌을 가진 2 마리의 새, 이제 기능에 몇 가지 문서가 있습니다.
이에 대한 답변을 수락 한 것을 알고 있지만, 이제 Excel-DNA 추가 기능을 통해 또는 내부에 인텔리 센스 서버를 등록하여 다른 엑셀 기능과 같이 인텔리 센스 스타일 완성 상자 팝업을 얻을 수있는 솔루션이 있습니다. 자신의 추가 기능. 여기를 참조하십시오 .
지금, 나는 그 일의 C #을 방법을 선호 - 그것은 엑셀-DNA, 구현이 그 모든 클래스 내부로 훨씬 간단 IExcelAddin
추가 기능 프레임 워크 집어 가지고있다 AutoOpen()
그리고 AutoClose()
당신은 /에 가까운 추가를 열 때 실행 방금이 필요합니다 그래서. :
namespace MyNameSpace {
public class Intellisense : IExcelAddIn {
public void AutoClose() {
}
public void AutoOpen() {
IntelliSenseServer.Register();
}
}
}
그런 다음 (그리고 이것은 github 페이지에서 가져온 것입니다) 함수에 ExcelDNA 주석을 사용하기 만하면됩니다.
[ExcelFunction(Description = "A useful test function that adds two numbers, and returns the sum.")]
public static double AddThem(
[ExcelArgument(Name = "Augend", Description = "is the first number, to which will be added")]
double v1,
[ExcelArgument(Name = "Addend", Description = "is the second number that will be added")]
double v2)
{
return v1 + v2;
}
ExcelDNA 주석을 사용하여 주석을 달면 인텔리 센스 서버가 인수 이름과 설명을 선택합니다.
There are examples for using it with just VBA too, but i'm not too into my VBA, so i don't use those parts.
Unfortunately there is no way to add Tooltips for UDF Arguments.
To extend Remou's reply you can find a fuller but more complex approach to descriptions for the Function Wizard at
http://www.jkp-ads.com/Articles/RegisterUDF00.asp
A lot of dancing around the answer. You can add the UDF context help, but you have to export the Module and edit the contents in a text editor, then re-import it to VBA. Here's the example from Chip Pearson: Adding Code Attributes
Also you can use, this Macro to assign Descriptions to arguments and the UDF:
Private Sub RegisterMyFunction()
Application.MacroOptions _
Macro:="SampleFunction", _ '' Your UDF name
Description:="calculates a result based on provided inputs", _
Category:="My UDF Category", _ '' Or use numbers, a list in the link below
ArgumentDescriptions:=Array( _ '' One by each argument
"is the first argument. tell the user what it does", _
"is the second argument. tell the user what it does")
End Sub
Credits to Kendall and the original post here. For the UDF Categories
@will's method is the best. Just add few lines about the details for the people didn't use ExcelDNA before like me.
Download Excel-DNA IntelliSense from https://github.com/Excel-DNA/IntelliSense/releases
There are two version, one is for 64, check your Excel version. For my case, I'm using 64 version.
Open Excel/Developer/Add-Ins/Browse and select ExcelDna.IntelliSense64.xll.
Insert a new sheet, change name to "IntelliSense", add function description, as https://github.com/Excel-DNA/IntelliSense/wiki/Getting-Started
Then enjoy! :)
I tried @ScottK's approach, first as a side feature of my functional UDF, then as a standalone _Help suffix version when I ran into trouble (see below). In hindsight, the latter approach is better anyway--more obvious to a user attentive enough to see a tool tip, and it doesn't clutter up the functional code.
I figured if an inattentive user just typed the function name and closed the parentheses while he thought it over, help would appear and he would be on his way. But dumping a bunch of text into a single cell that I cannot format didn't seem like a good idea. Instead, When the function is entered in a cell with no arguments i.e.
= interpolateLinear()
or
= interpolateLinear_Help()
a msgBox opens with the help text. A msgBox is limited to ~1000 characters, maybe it's 1024. But that's enough (barely 8^/) for my overly tricked out interpolation function. If it's not, you can always open a user form and go to town.
The first time the message box opened, it looked like success. But there are a couple of problems. First of course, the user has to know to enter the function with no arguments (+1 for the _Help suffix UDF).
The big problem is, the msgBox reopens several times in succession, spontaneously while working in unrelated parts of the workbook. Needless to say, it's very annoying. Sometimes it goes on until I get a circular reference warning. Go figure. If a UDF could change the cell formula, I would have done that to shut it up.
I don't know why Excel feels the need recalculate the formula over and over; neither the _Help standalone, nor the full up version (in help mode) has precedents or dependents. There's not an application.volatile statement anywhere. Of course the function returns a value to the calling cell. Maybe that triggers the recalc? But that's what UDFs do. I don't think you can not return a value.
Since you can't modify a worksheet formula from a UDF, I tried to return a specific string --a value --to the calling cell (the only one you can change the value of from a UDF), figuring I would inspect the cell value using application.caller on the next cycle, spot my string, and know not to re-display the help message. Seemed like a good idea at the time--didn't work. Maybe I did something stupid in my sleep-deprived state. I still like the idea. I'll update this when (if) I fix the problem. My quick fix was to add a line on the help box: "Seek help only in an emergency. Delete the offending formula to end the misery.
그 동안 Application.MacroOptions 접근 방식을 시도했습니다. 매우 쉽고 전문적으로 보입니다. 해결해야 할 한 가지 문제입니다. 나중에 그 접근 방식에 대한 별도의 답변을 게시 할 것입니다.
참고 URL : https://stackoverflow.com/questions/4262421/how-to-put-a-tooltip-on-a-user-defined-function
'Nice programing' 카테고리의 다른 글
링크로 전화하지 않고 스카이프 채팅을 시작하는 방법 (0) | 2020.10.31 |
---|---|
XAML에서 컨트롤 중심을 회전하는 방법 (0) | 2020.10.31 |
푸시 알림을위한 장치 토큰 가져 오기 (0) | 2020.10.31 |
CMake로 컴파일러의 C ++ 11 지원을 감지하는 방법 (0) | 2020.10.31 |
함수의 PHP 액세스 전역 변수 (0) | 2020.10.31 |