vba 什么原因导致“找不到项目或库错误”以及如何防止它发生?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45593868/
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
What causes 'can't find project or library error' and how to prevent it from happening?
提问by Damian M
I'm having an issue with tool I developed in excel for one of our offices. It is a big enough file with couple of macros in it, but it works smooth day to day.
我在 Excel 中为我们的一个办公室开发的工具出现问题。它是一个足够大的文件,其中包含几个宏,但它每天都可以顺利运行。
However every few days file will through error 'Can't find project or library' and file will crash. I know the standard guides are that when this error appears, it is to go to vba>tools>referneces and uncheck the missing library, however this is not the case in here. Simply when this happens file crashes and restarts and if it will happen once, every other attempt to open back the file will result in same error in crash. I mean file can be absolutely fine, you will save it, go back to it and error happens. So I always have to recover the file which absolutely destroys it, however I can at least recover from it information uploaded there by the users and copy it into the template.
但是,每隔几天文件就会出现“找不到项目或库”错误并且文件会崩溃。我知道标准指南是当这个错误出现时,它是去 vba>tools>referneces 并取消选中丢失的库,但是这里不是这种情况。只是当这种情况发生时,文件会崩溃并重新启动,如果它会发生一次,那么每次打开文件的其他尝试都会导致崩溃时出现相同的错误。我的意思是文件可以绝对没问题,您将保存它,返回它并发生错误。所以我总是必须恢复绝对破坏它的文件,但是我至少可以从中恢复用户上传的信息并将其复制到模板中。
So 2 questions I have is what is causing this to happen? Both myself and the other office are using the same version of excel so compatibility should not be an issue.
所以我有两个问题是什么导致这种情况发生?我和其他办公室都使用相同版本的 excel,因此兼容性应该不是问题。
2 questions is is there anything that can be done to prevent this error from happening.
2个问题是有什么可以做的来防止这个错误的发生。
回答by user10477032
I have exactly this problem. As stated, once the error occurs, it it results in a permanent "unfixable" loop. I use powerquery and linked data and this appears to randomly "damage" the file as described - most frequently when excel crashes for some reason.
我正好有这个问题。如前所述,一旦发生错误,就会导致永久的“无法修复”循环。我使用 powerquery 和链接数据,这似乎会按照描述随机“损坏”文件 - 最常见的是当 excel 由于某种原因崩溃时。
I have found either of the following to work: - Open the file on a different computer that is not on the LAN. This appears to be a key requirement. - Open the file with "Excel Online"
我发现以下任一方法可行: - 在不在 LAN 上的另一台计算机上打开文件。这似乎是一个关键要求。- 使用“Excel Online”打开文件
In each case, simply open the file and save it with a new name. Move the new file back to the work PC and it will once more open perfectly.
在每种情况下,只需打开文件并使用新名称保存即可。将新文件移回工作 PC,它将再次完美打开。
On rare occasions (if powerquery is in use), it is necessary to "refresh all" data connections before saving the new file.
在极少数情况下(如果正在使用 powerquery),有必要在保存新文件之前“刷新所有”数据连接。
As a bonus, the new file is often smaller than the original.
作为奖励,新文件通常比原始文件小。
回答by nishit dey
This worked for me:
这对我有用:
In VB go to Tools ? References 1) Uncheck the library "Crystal Analysis Common Controls 1.0". Or any library. Just leave these 5 references: 1) Visual Basic For Applications (This is the library that defines the VBA language.) 2) Microsoft Excel Object Library (This defines all of the elements of Excel.) 3) OLE Automation (This specifies the types for linking and embedding documents and for automation of other applications and the "plumbing" of the COM system that Excel uses to communicate with the outside world.) 4) Microsoft Office (This defines things that are common to all Office programs such as Command Bars and Command Bar controls.) 5) Microsoft Forms 2.0 This is required if you are using a User Form. This library defines things like the user form and the controls that you can place on a form. Then Save.
在 VB 中转到工具?参考文献 1) 取消选中库“Crystal Analysis Common Controls 1.0”。或任何图书馆。只留下这 5 个引用:1) Visual Basic For Applications(这是定义 VBA 语言的库。)2)Microsoft Excel 对象库(这定义了 Excel 的所有元素。)3)OLE 自动化(这指定了类型用于链接和嵌入文档以及其他应用程序的自动化以及 Excel 用来与外部世界通信的 COM 系统的“管道”。) 4) Microsoft Office(这定义了所有 Office 程序通用的东西,例如命令栏和命令栏控件。) 5) Microsoft Forms 2.0 如果您使用的是用户表单,则这是必需的。该库定义了诸如用户表单和可以放置在表单上的控件之类的内容。然后保存。
回答by S Meaden
I've had similar nasty issues.
我也遇到过类似的讨厌的问题。
First thing to do is use the CodeCleaner a free utility from AppsProThis will export your modules and then re-import them, because internally they get a lot of binary "lint" which can cause problem.
首先要做的是使用来自 AppsPro 的免费实用程序 CodeCleaner这将导出您的模块,然后重新导入它们,因为在内部它们会得到很多可能导致问题的二进制“lint”。
Second thing to suggest is start breaking up your code base. So start removing modules to see which module is the offender. Horrible I know but how can you tell otherwise where the problem is.
建议的第二件事是开始分解您的代码库。因此,开始删除模块以查看哪个模块是违规者。可怕的我知道,但你怎么能知道问题出在哪里。
Third suggestion is to always fully qualify your functions. So instead of Len(sMyString) write VBA.Len(sMyString) that helps prevent false negative compile errors.
第三个建议是始终完全限定您的功能。因此,代替 Len(sMyString) 编写 VBA.Len(sMyString) 有助于防止误报编译错误。