vba 错误 53 找不到文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20523375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error 53 File not found
提问by sion_corn
I have an Access 2003 DB, which has a VBA module. The module function points to an Excel file.
我有一个 Access 2003 DB,它有一个 VBA 模块。模块函数指向一个 Excel 文件。
The function is calling the Excel file through the command line like this:
Shell "Excel \\server\dir\filename.xls", vbMaximizedFocus
该函数通过命令行调用 Excel 文件,如下所示:
Shell "Excel \\server\dir\filename.xls", vbMaximizedFocus
The DB opens, the function gets triggered, and I get Run-timer error '53': File not found
数据库打开,函数被触发,我得到 Run-timer error '53': File not found
I know that the Excel file exists, and I am able to open it. I have the security permissions to be able to access folders in the filepath.
我知道 Excel 文件存在,我可以打开它。我具有能够访问文件路径中的文件夹的安全权限。
What I already tried:
我已经尝试过的:
decompile+compact+recompile the DB, using the instructions here.
I am still getting the same error. Can anyone suggest other causes/solutions?
我仍然遇到同样的错误。任何人都可以提出其他原因/解决方案吗?
minor edit- content remains the same.
小编辑- 内容保持不变。
采纳答案by HansUp
I can't reproduce the file not found error. I adapted your code as follows, but it opens the workbook file without error.
我无法重现找不到文件的错误。我按如下方式调整了您的代码,但它打开工作簿文件没有错误。
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
Alternatively, you could create an Excel application instance and then open the file. However I'm skeptical whether that would avoid the not found error.
或者,您可以创建一个 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
回答by Trace
Refer to the mapped network drive (letter). Check your immediate window:
请参阅映射的网络驱动器(字母)。检查您的即时窗口:
?dir("N:/dir\filename.xls")
You can also open a workbook as follows (if you want more flexibility):
您还可以按如下方式打开工作簿(如果您想要更大的灵活性):
Dim oExcel As Excel.Application
Set oExcel = CreateObject("Excel.Application")
oExcel.visible = true
oExcel.Workbooks.Open ("\server\dir\filename.xls")
oExcel.Quit 'close