我一直在寻找答案,但在任何地方都找不到。
我有一个 Excel 文件,它使用 ADODB 连接来读取和写入已关闭的工作簿。这一切在我的笔记本电脑上运行良好,使用本地存储的文件进行读取和写入。 (Office 专业增强版 2016,Win32)。
但是当我将文件复制到网络时,Excel 在尝试打开连接和文件时崩溃。
网络有 Office Professional Plus 2010 32 位版本,并且位于远程桌面上。
我使用的代码如下
Sub GetData()
'To get data from closed Store Master File
Dim strSQL As String ' used to execute a request
Dim strSfile As String ' the name of the source file
Dim strServer As String ' the drive where the source file is located
Dim strpath As String ' the path on the drive where the file is located
Dim sFile As String ' concat of server/path/file
Dim constr As String ' the connection string
Dim cnn As New ADODB.Connection ' the connection
'Set connection to the Store Master file
strServer = "P:\"
strpath = Sheets("Control").Range("A2").Value
strSfile = Sheets("Control").Range("A5").Value
sFile = strServer & strpath & strSfile
constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & sFile & "';Extended Properties=""Excel 12.0;HDR=YES;"";"
'Open connection
cnn.Open constr ' the problem line
'.... other lines of code
cnn.Close
End Sub
在尝试调试问题时,这
cnn.Open constr
行代码是 Excel 崩溃的地方,因此没有可用的 VBA 错误数据。
我将 sfile 变量的结果返回到立即窗口,复制该结果并尝试打开 Excel 文件。这有效,所以我知道这不是文件名和路径的问题。
事实上,我有一些可以打开该文件的 vba 代码,并且效果很好。
如上所述,问题在于打开与该关闭文件的 ADODB 连接。代码在本地运行良好(文件存储在本地)。
我所拥有的唯一错误信息似乎是:
问题事件名称:APPPCRASH 应用程序名称: EXCEL.EXE 应用程序版本:14.0.7256.5000 故障模块:mso.dll 故障模块版本:14.0.7257.5000 异常代码:c00000005 异常偏移:00bb441f 操作系统版本:6.1.7601.2.1.0.16.7 区域设置 ID:3081
有关问题的其他信息: LCID:1033 斯库西德:1033
有什么帮助/指导/建议吗?将不胜感激。
抱歉带来坏消息,但这可能是由于访问未分配的内存引起的。
我搜索“adodb 异常代码:c00000005”并找到了this。