问题描述
因此,我正在使用VBA代码打开Excel文件,并将数据下载到包含该代码的工作表中.
So I am using VBA code to open a Excel file, and download data into the worksheet that contains the code.
成功了,现在我得到了错误:
It worked, now I get the error:
我打开代码以查看它的下落. (我认为文件可能已更改位置或名称已更改.)当我遍历代码(使用F8键)时,我立即在代码的第一行(SUB TITLE)上看到错误,并将其标记为黄色. /p>
I opened the code to see where it is falling. (I thought maybe the file has changed location or the name has been changed.) When I go through the code (using F8), I immediately get the error on the first line of code (SUB TITLE) and it is marked yellow.
推荐答案
"访问文件时出错.网络连接可能已丢失"
当VB编辑器检测到源代码(您在编辑器中看到的文本)与也保存在工作簿中的已编译二进制"p"代码之间存在差异时,可能引发此错误(以及其他一般错误消息).这种差异情况通常被称为腐败"事件.工作簿.
"Error accessing file. Network connection may have been lost"
This (and other generic error messages) can be thrown when the VB Editor detects a discrepancy between the source code (the text you see in the editor) and the compiled binary 'p' code also saved in the workbook. This discrepancy situation is commonly referred to as a "corrupt" workbook.
临时修复程序是一个接一个地导出模块,表单和类,创建一个新的工作簿,然后将它们重新导入.此时,您现在至少可以在以下位置编辑源代码以解决根本原因.
A temporary fix is to export the modules, forms, and classes one by one, create a new workbook and import them back in. At this point you can now at least edit your source code in order to address the root cause.
但是,如果源代码中未解决损坏的根本原因,则每当VB编辑器下一次运行/编译代码的麻烦部分时,都会重新引入已编译的二进制"p"代码中的损坏.
However, if the root cause of the corruption is not dealt with in your source code, then whenever the VB Editor next runs/compiles the troublesome portion of your code the corruption in the compiled binary 'p' code will be reintroduced.
只有当您保存并重新打开工作簿后,这种损坏才会变得明显,此时VB编辑器将检测到源代码与工作簿中保存的二进制"p"代码之间的差异,并再次引发错误.
This corruption will become apparent only once you have saved and reopened the workbook, at which point the VB Editor will detect the discrepancy between the source code and the binary 'p'code saved in the workbook and throw the error once again.
我在下一篇文章中的解决方案深入了解了由于使用IMPLEMENTS
语句的类中无意中创建循环依赖项而导致此错误的一个原因:
My solution on the following post gives insight into one such cause of this error due to inadvertently creating a circular dependency in classes that use the IMPLEMENTS
statement:
这篇关于访问文件时出错.网络连接可能已丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!