【问题标题】:Error 53 File not found错误 53 找不到文件
【发布时间】:2013-12-29 16:13:40
【问题描述】:

我有一个 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.

我仍然遇到同样的错误。任何人都可以提出其他原因/解决方案吗?

小修改 - 内容保持不变。

【问题讨论】:

  • 你能从文件资源管理器窗口访问文件\\server\dir\filename.xls吗?

标签: ms-access vba


【解决方案1】:

我无法重现文件未找到错误。我对您的代码进行了如下调整,但它打开工作簿文件时没有错误。

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 应用程序实例,然后打开该文件。但是我怀疑这是否会避免 not found 错误。

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

【讨论】:

    【解决方案2】:

    请参阅映射的网络驱动器(字母)。检查您的即时窗口:

    ?dir("N:/dir\filename.xls") 
    

    您还可以按如下方式打开工作簿(如果您想要更大的灵活性):

    Dim oExcel As Excel.Application
    Set oExcel = CreateObject("Excel.Application")
    
    oExcel.visible = true
    oExcel.Workbooks.Open ("\\server\dir\filename.xls")
    
    oExcel.Quit 'close 
    

    【讨论】:

    • 路径无法识别的最终原因是什么?
    • 由于某种原因,在 shell 中输入“excel”不会启动 excel。但如果我输入了 excel.exe 的完整路径,它就能启动。由于不同机器上的路径可能不同,并且考虑到未来的软件升级,我决定只调用 excel 对象。
    猜你喜欢
    • 2018-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-16
    • 2015-12-27
    • 2018-06-08
    • 1970-01-01
    • 2018-01-03
    相关资源
    最近更新 更多