Excel VBA编译抛出“用户定义的类型未定义”错误,但不去goto代码行 [英] Excel VBA Compile throws a "User-defined type not defined" error but does not goto offending line of code

查看:725
本文介绍了Excel VBA编译抛出“用户定义的类型未定义”错误,但不去goto代码行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是编译 Excel VBA项目时的症状。发生以下错误:

This is a symptom specifically when compiling an Excel VBA project. The following error occurs:

未定义用户定义类型

但是,生成此错误的代码不会由编译器突出显示,因此我无法识别问题。

However, the code that produces this error is not highlighted by the compiler and so I cannot identify the issue.

这是一个用户定义类型未定义错误,我曾经看到过的简单问题,如命名的东西 As Strig 而不是 As String 。然而,这个特定的错误只是在 Debug>编译VBAProject 菜单选项,当错误消息框弹出时,它不会突出显示错误发生的代码行。

This is a "User-defined type not defined" error that I have seen before with simple issues such as naming something As Strig instead of As String. However this particular error is only popping up during the Debug > Compile VBAProject menu option and when the error message box pops up it does not highlight the line of code that the error is occuring in.

很多研究我发现这个错误可能与缺失的引用相关,我已经排除了这一点,因为我已经包括所有需要的引用和Toolbox对象。

After a lot of research I have found that this bug can be related to missing references and I have ruled this out as I have included all needed references and Toolbox objects.

我没有丢失任何明显丢失的 Dim 语句我已经添加了选项显式到所有代码页确保没有丢失。运行编译时,错误仍然会显示。

To ensure I wasn't missing any obvious missing Dim statements I have added Option Explicit to all code pages (forms included) to make sure nothing was missing. The error still shows when running a compile.

还有这个已知的错误说明由于使用二进制兼容性的 VB6 项目,已知会发生此问题:

There is also this known bug that states the issue has been known to happen because of the VB6 projects using binary compatibility:


关闭二进制兼容性并编译项目。 Visual Basic
将突出显示包含未定义的用户定义类型
的代码行。解决问题后,可以重新启用Binary兼容性

Turn off Binary Compatibility and compile the project. Visual Basic will highlight the line of code that contains the User Defined Type that is not defined. After resolving the problem, Binary Compatibility can be turned back on.

通过此问题和答案,但是,我找不到此选项标准Excel VBA 编辑器。

I found this article via this Question and Answer, however, I cannot find this option in the standard Excel VBA editor.

我从Google搜索和其他问题中得知,我不是唯一遇到此问题的人。

I know from Google searches and other questions that I am not the only one who has had this issue.

我已经尝试过手动修改代码,很多行都可行。

I have tried going through the code manually but there are simply too many lines to feasibly do so.

有没有办法关闭Excel VBA项目中的二进制兼容性?如果人们无法调试到需要改变的地方,那么人们如何找到这个令人讨厌的代码行?任何帮助都会很可爱!

Is there a way of turning off Binary Compatibility in Excel VBA projects? How do people find this offending line of code if they can't debug to what they need to change? Any help would be lovely!

提前感谢。

我已经找到令人讨厌的代码行,所以我的特定问题解决问题仍然在这里删除该特定的行后 - 这是一个错误的控件名称在它的代码中被引用的表单。这仍然没有解决你将如何去发现这个令人讨厌的代码的问题的特定问题。当这个错误发生时,我们能找到一个好的方法来找到有问题的代码,以便未来的其他人可以避免这种痛苦吗?

I have found the offending line of code and so my particular issue is solved The problem is still here after removing that particular line - it was a mispelt control name on a form being referenced in it's code. This still does not solve the particular issue of how you would go about finding this offending code was the issue. Are we able to find a good way of finding the offending code when this bug happens so others in the future can avoid this agony?

推荐答案

p>由于听起来你已经尝试了许多不同的电位解决方案,你现在可能必须这样做是有条不紊的。

Since it sounds like you've tried many different potentional solutions, you'll probably have to do this the long methodical way now.

创建一个新的空白工作簿。然后一块一块地复制你的旧工作簿。添加一个引用,写一点代码来测试一下。确保它编译,确保它运行。添加一个子或函数,再次,写一个测试子运行它,也保证它编译。重复此过程,慢慢添加和测试所有内容。

Create a new blank workbook. Then piece by piece copy your old workbook into it. Add a reference, write a little bit of code to test it. Ensure it compiles, ensure it runs. Add a sub or function, again, write a little test sub to run it, also ensure it compiles. Repeat this process slowly adding and testing everything.

您可以先尝试更大的块,然后当发现一个触发问题,删除它,

You can speed this up a bit by first trying larger chunks, then when you find one that triggers the problem, remove it and break it into smaller peices for testing.

你会找到犯罪者,或者你会有一个新的工作簿,神奇地没有问题。后者将是由于在工作簿文件中的某种隐藏损坏,可能在二进制vbproject部分。

Either you will find the offender, or you'll have a new workbook that magically does not have the problem. The latter would be due to some sort of hidden corruption in the workbook file, probably in the binary vbproject part.

欢迎来到调试的世界,没有调试器或其他有用的工具为你做重的提升!

Welcome to the world of debugging without debuggers or other helpful tools to do the heavy lifting for you!

这篇关于Excel VBA编译抛出“用户定义的类型未定义”错误,但不去goto代码行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆