【发布时间】:2014-02-07 03:15:49
【问题描述】:
当我调用没有参数的函数时,我不确定为什么会收到错误“参数不是可选的”:
Sub CreateQACheck()
' ...do stuff
Dim QAFileName As String
QAFileName = FindQACheckFile
'...
End Sub
Function FindQACheckFile() As String
' Do stuff...
FindQACheckFile = something
End Function
我应该把不用的参数放在那里吗?
编辑:我发现了问题(缺少括号),我将在下面发布答案,但这里是出现问题的代码:
Function FindQACheckFile() As String
Dim QAFileDir As String, QAFileName As String, QAFilePath As String
QAFileDir = "c:\something"
If Len(Dir(QAFileDir)) = 0 Then
QAFileDir = "c:\somethingelse"
End If
QAFileName = "qacheckfile.xlsm"
QAFilePath = QAFileDir + QAFileName
If Len(Dir(QAFilePath)) = 0 Then ' If it's not there, gotta ask the user where it is
MsgBox ("I can't find the QA check file! Please let " + MGlobal.DEVNAME + " (" + MGlobal.DEVEMAIL + ") know, but for now point me in the right direction...")
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
.AllowMultiSelect = False
If .Show = -1 Then
QAFilePath = .SelectedItems
End If
End With
End If
FindQACheckFile = QAFilePath
End Function
【问题讨论】:
-
在整个项目中检查某种重复名称(可能在模块、类等中)。该特定代码没有任何问题,除非有其他干扰..
-
您的代码在我看来是正确的。您确定您没有在其他地方收到此错误吗?还是您创建了多个同名函数?
-
工具 - 选项 - 常规 - 错误捕获 - 中断所有错误。打开该选项。您可能在另一个隐藏的点上遇到了错误。
-
不要说
' ...do stuff或FindQACheckFile = something你能告诉我们确切的代码吗?