这让我疯了。
使用VBA Access,我正在尝试为我们正在开发的数据库应用程序设置回归测试套件。我想遍历一个表,并使用Application.Run调用表中列出的每个模块和函数(这样,当开发人员创建新功能时,他们可以创建他们的回归测试模块,并将其列在表中)。
我想我会用Application.Run来做这件事。
我的代码片段有效:
If folderName <> "" Then
Dim test1 As String: test1 = "regCOTSImporter"
Dim test2 As String: test2 = "regressionTestCOTS"
Application.Run regCOTSImporter.regressionTestCOTS(foldername)
End If
现在,我会假设
Application.Run regCOTSImporter.regressionTestCOTS, foldername
也可以工作,但事实并非如此,因为VBA未能找到声称该参数不是可选的过程(即使Application.Run的文档列出了作为参数的其他参数......)
但是,理想情况下我希望regCOTSImporter和regressionTestCOTS分别被test1和test2替换,如上面的Dim'd - 这样我就从DB加载它们。但是,如果我执行以下操作:
Application.run test1 & "." test2 & "(" & foldername & ")"
我收到一条消息,说无法找到该程序。为了能够从String调用此module.function,我需要做什么?
提前致谢!
第二个例子的正确版本是
Application.Run "regCOTSImporter.regressionTestCOTS", foldername
因此,您可以简单地使用
Application.run test1 & "." test2, foldername
对于一般情况,因为test1 & "." test2
已经是一个字符串。
Application.Run "'" & test1 & "." & test2 & "(""" & FolderName & """)'"
你提供的字符串看起来像这样
'regCOTSImporter.regressionTestCOTS("testfname")'
假设你的FolderName
变量设置为testfname