小编Kel*_*eck的帖子

如何将数组传递给VBA中的函数?

我正在尝试编写一个接受数组作为参数的函数.该数组可以包含任意数量的元素.

Function processArr(Arr() As Variant) As String
    Dim N As Variant  
    dim finalStr as string      
    For N = LBound(Arr) To UBound(Arr)
        finalStr = finalStr & Arr(N)
    Next N
    processArr = finalStr
End Function
Run Code Online (Sandbox Code Playgroud)

以下是我尝试调用该函数的方法:

Sub test()
    Dim fString as string
    fString = processArr(Array("foo", "bar"))
End Sub
Run Code Online (Sandbox Code Playgroud)

我收到一个错误说:

编译错误:类型不匹配:数组或用户定义的预期类型.

我究竟做错了什么?

arrays ms-access vba function access-vba

26
推荐指数
2
解决办法
10万
查看次数

从快捷键运行宏时不出现输入框

我有一个简单的小 Excel 宏,用于打开模板、询问文件名并保存文件。它从 Microsoft VBA 窗口运行没有问题,但当从 Excel 使用快捷键时,它会打开文件,但不显示输入框。

Sub NewCommentSheet()
'
' NewCommentSheet Macro
' Opens the Comments and Recheck template. A dialog box asks for the data module name,
' which is then used for the filename of the new comment sheet.
'
' Keyboard Shortcut: Ctrl+Shift+N
'
    'Opens the file

    Workbooks.Open Filename:= _
        "C:\Users\Kelly.Keck\Documents\Projects\SBIR\QA Notes\Comments and Recheck Template.xlsx"

    'Defines variables. moduleName comes from the input box. newFileName uses moduleName _
    to create a filename: "Comments for [moduleName].xslx"

    Dim …
Run Code Online (Sandbox Code Playgroud)

excel vba inputbox

4
推荐指数
1
解决办法
1785
查看次数

标签 统计

vba ×2

access-vba ×1

arrays ×1

excel ×1

function ×1

inputbox ×1

ms-access ×1