我有一个Access 2003 DB,其中有一个VBA模块。模块功能指向一个Excel文件。

该函数通过命令行调用Excel文件,如下所示:Shell "Excel \\server\dir\filename.xls", vbMaximizedFocus
数据库打开,函数被触发,我得到Run-timer error '53': File not found
我知道Excel文件存在,并且可以打开它。我具有安全性权限,才能访问文件路径中的文件夹。

我已经尝试过的:

反编译+压缩+重新编译数据库using the instructions here.

我仍然遇到相同的错误。谁能提出其他原因/解决方案?

次要编辑-内容保持不变。

最佳答案

我无法重现“找不到文件”错误。我按如下方式修改了您的代码,但是它打开了工作簿文件,没有错误。

Const cstrFile = "\\HP64\share\Access\temp.xls"
If Len(Dir(cstrFile)) = 0 Then
    MsgBox "File '" & cstrFile & "' not found."
Else
    Shell "Excel " & cstrFile, vbMaximizedFocus
End If

或者,您可以创建一个Excel应用程序实例,然后打开该文件。但是我对此是否会避免未发现的错误表示怀疑。

Dim objExcel As Object 'Excel.Application
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Open cstrFile

' do stuff here
objExcel.Quit
Set objExcel = Nothing

10-07 19:39
查看更多