Error accessing file. Network connection may have

2020-04-21 01:01发布

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:

Error accessing file. Network connection may have been lost.

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.

标签: excel vba
1条回答
我只想做你的唯一
2楼-- · 2020-04-21 01:54

"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.

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.

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.

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:

IMPLEMENTS circular dependency issue

查看更多
登录 后发表回答