注册不带参数的 Excel UDF [英] Register Excel UDF without arguments

查看:20
本文介绍了注册不带参数的 Excel UDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多用户定义的带参数和不带参数的函数.我使用这篇文章中的 CUdfHelper http://www.jkp-ads.com/articles/RegisterUDF00.asp 用于注册功能.

I has many user define function with arguments and without. I use CUdfHelper from this article http://www.jkp-ads.com/articles/RegisterUDF00.asp for register function.

已注册的函数要求参数作为参数,即使它们不是.

Registered function ask arguments for arguments, even if they are not.

以不带参数的函数为例:

Example my fuction without arguments:

Public Function getProjects()
   getProjects = Utils.execute("getProjects", "getWSEntitiesData")
End Function

在 MyFunction.c 上

On MyFunction.c

#include <windows.h>

#define DLL_EXPORT __declspec(dllexport)


DLL_EXPORT void getProjects() {
    return;
}

在 MyFunction.dll 上编译

compile on MyFunction.dll

我使用这些参数注册函数.

I register the function with these parameters.

SetGlobalName = Application.ExecuteExcel4Macro("MyFunction.dll", "getProjets", "P", "getProjects", "", 1, "MyFunctionCategory", "", "", "Return list projects")

如果我注册为

SetGlobalName = Application.ExecuteExcel4Macro("MyFunction.dll", "getProjets", "P", "getProjects",, 1, "MyFunctionCategory", "", "", "Return list projects")

函数参数对话框显示的都是一样的.

Function argument dialog is displayed all the same.

如果我注册为

SetGlobalName = Application.ExecuteExcel4Macro("MyFunction.dll", "getProjets", "P", "getProjects",, 1, "MyFunctionCategory")

函数参数对话框未显示,但描述不再可用.

Function argument dialog isn't displayed, but the description is no longer available.

REGISTER() 参数

REGISTER() Arguments

  1. dll 的路径和名称
  2. 要调用的函数名称
  3. 输入字符串
  4. 要在 Excel 单元格中使用的名称
  5. 要在函数向导中使用的参数列表
  6. 宏类型(2 个用于函数,2 个用于命令)
  7. 要将函数添加到哪个函数向导类别
  8. 如果注册的函数是命令,则为快捷文本
  9. 帮助文件的路径
  10. 显示在函数向导中的函数帮助

11-30 之后函数向导中每个参数的帮助文本.

11-30 onwards help text for each argument in the function wizard.

我认为问题出在参数上,因为默认情况下它设置为空字符串,我不知道如何更改函数的参数.

I think the problem is in the arguments, as by default it is set to an empty string, and I can not figure out how to change the parameters to the function.

在 CUdfHelper 上

On CUdfHelper

' structure definition
Private Type REGARG
    sDllName As String
    sDllProc As String
    sArgType As String
    sFunText As String
    **sArgText As String**
    iMacType As Integer
    vCatName As Variant
    sKeyText As String
    sHlpPath As String
    **sFunHelp As String**
    aArgHelp(1 To 20) As String
End Type

如何正确设置参数,不出现窗口,并保存描述?

How to correctly set the parameters so that the window does not appear, and stores the description?

推荐答案

如果向 ExecuteExcel4Macro 注册函数并设置函数描述.但是,在 XLL 加载项中,您可能会遇到 Excel API 中的错误.如果在描述属性中具有非空字符串的 ADXExcelFunctionDescriptor 中提到无参数函数,则会显示该错误.如果是这种情况,您将获得另一个版本的函数参数"对话框.

If register function with ExecuteExcel4Macro and set Function Description. In an XLL add-in, however, you may run into a bug in the Excel API. The bug shows itself if a parameterless function is mentioned in an ADXExcelFunctionDescriptor that has a non-empty string in the Description property. If this is the case, you'll get another version of the Function Arguments dialog.

也就是说,要绕过该问题,您需要将 ADXExcelFunctionDescriptor.Description 属性留空.

That is, to bypass that issue, you need to leave the ADXExcelFunctionDescriptor.Description property empty.

https://www.add- 上查找in-express.com/docs/net-excel-udf-tips.php

这篇关于注册不带参数的 Excel UDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆