2

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.

Community
  • 1
  • 1
Peter
  • 65
  • 1
  • 12
  • Hardly a fix, but can't you try to import your data into a new wb and see if the problem remains? – JvdV Apr 03 '19 at 08:05
  • Thanks for the reply, but unfortunately that doesn't seem to work. – Peter Apr 03 '19 at 08:14
  • 1
    When it fails at the very first of the macro must be a syntax error or lack of references. Go check your references to see if there are some missing. – Damian Apr 03 '19 at 08:17
  • That did seem to do the trick, I'm not quite sure why the was no problem in the past.. Thanks anyway! – Peter Apr 03 '19 at 08:20
  • 1
    This happens when you change your version of some software.. Maybe the last person who used it had 16 and you have the older one, 15. When moving from 15 to 16 in my experience nothing happens but going backwards always give errors (for MS software). Other libraries from different software could be causing the problem when trying different versions. You must uncheck the missing ones and find your current version for the ones you just unchecked. – Damian Apr 03 '19 at 08:24

1 Answers1

2

"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

Community
  • 1
  • 1
MonkeyFace
  • 108
  • 9