简体   繁体   English

将 Excel VBA Analysis ToolPack “Fourier” Sub 转换为 UDF Function

[英]Convert Excel VBA Analysis ToolPack "Fourier" Sub into a UDF Function

I would like to create a UDF in VBA making use of Excel's "Fourier" sub available in ATPVBAEN.XLAM Analysis ToolPack VBA. I thought a way to do this would be to create on the fly a new WorkSheet, run the sub with the output directed to that new Worksheet, copy the results into an array, delete the created worksheet, and return the array.我想在 VBA 中创建一个 UDF,利用 ATPVBAEN.XLAM 分析工具包 VBA 中可用的 Excel 的“傅立叶”子程序。我认为一种方法是动态创建一个新的工作表,使用 output 运行子程序指向该新工作表,将结果复制到数组中,删除创建的工作表,然后返回数组。 However, I seem to have run into a problem where I cannot create a new WorkSheet in a call from a function in the workbook;但是,我似乎遇到了无法在工作簿中的 function 调用中创建新工作表的问题; a call to the following function from a cell in the workbook does not create a new worksheet:从工作簿中的单元格调用以下 function 不会创建新工作表:

Function addWS() As Variant
  Dim WS As Worksheet
  With ThisWorkbook
    Set WS = .Worksheets.Add
  End With
End Function

How do I overcome this?我该如何克服这个问题?

You can't transform the ToolPack's Fourier Transform into a UDF.您无法将 ToolPack 的傅立叶变换转换为 UDF。

You can however implement the Fourier transform in some other way.但是,您可以通过其他方式实现傅里叶变换。

  1. Define a UDF in VBA (see eg this answer and the linked code .在 VBA 中定义一个 UDF(参见例如这个答案链接的代码

  2. Use the recently released Excel LAMBDA functions to define a new custom function (see eg this repository ).使用最近发布的 Excel LAMBDA 函数来定义新的自定义 function(例如,参见此存储库)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM