我正在尝试编写一个接受数组作为参数的函数.该数组可以包含任意数量的元素.
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)
我收到一个错误说:
编译错误:类型不匹配:数组或用户定义的预期类型.
我究竟做错了什么?
我有一个简单的小 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)