所以这就是错误:64-BitVBA主机(例如Access 365 64位或Excel 2016 64位)创建类模块SomeClass
:
' this needs to be here to trigger the bug:
Private Sub Class_Terminate()
End Sub
然后是一些模块Test
:
Function ReturnFalse(o As Object) As Boolean
ReturnFalse = False
End Function
Sub Test()
Debug.Print ReturnFalse(New SomeClass)
If ReturnFalse(New SomeClass) Then
Debug.Print True
Else
Debug.Print False
End If
End Sub
现在,如果您正在使用32-bitVBA主机并在立即窗口中运行“测试”,预期结果显示:
False
False
但是,如果您使用的是64-bitVBA主机,然后就出来了:
False
True
除非您删除或重命名Class_Terminate()
sub,在这种情况下会出现正确的输出。
我已经将错误追溯到这个最小的示例。显然,问题似乎是使用临时对象(new SomeClass
这里)打破了评估IF
条件以某种方式,使得条件的值看起来是True
没关系。
好吧,这是一个严重的错误,因为 64 位编译器太疯狂了IF
有麻烦了。
All IF
?关于什么WHILE
?
While ReturnFalse(New SomeClass)
Debug.Print "Oh no!"
Wend
Yes, WHILE
也有麻烦,因为这会打印“哦不!”循环中。
这很麻烦,我可以在任何地方重现它:
- 适用于 Microsoft 365 MSO 的 Microsoft® Access® (16.0.14026.20294) 64 位
- Microsoft Access 2016 MSO (16.0.9029.2167) 64 位
- Microsoft Access 2013 (15.0.4420.1017) MSO (15.0.4420.1017) 64 位
..而且还在Excel当然。
摘要:从2013年开始,我在所有版本的Office中都发现了这个bug,它可能至少有8年了。
好的,这个错误之前影响过其他人吗?是的:
去年的这篇文章:
VBA 在 If 语句中采用错误分支 - 严重的编译器错误? https://stackoverflow.com/questions/65041832/vba-takes-wrong-branch-at-if-statement-severe-compiler-bug/68032045#68032045
excel.uservoice.com 中的这篇文章(显然是微软的用户建议箱之类的)来自2018年10月:
https://excel.uservoice.com/forums/304921-excel-for-windows-desktop-application/suggestions/35735881-fix-inlined-member-calls-on-user-objects-on-64-bi https://excel.uservoice.com/forums/304921-excel-for-windows-desktop-application/suggestions/35735881-fix-inlined-member-calls-on-user-objects-on-64-bi
好吧,让我们提交一份错误报告。
https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-mso_mac-mso_mac2016/how-do-i-report-vba-bugs/bb4e5dea-9996-4232-9b5b-7dd57f76736c https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-mso_mac-mso_mac2016/how-do-i-report-vba-bugs/bb4e5dea-9996-4232-9b5b-7dd57f76736c
如果在与其他人一起测试后,代码失败了,但实际上不应该失败,您可以使用 Excel 中的“微笑”按钮直接向 Microsoft 报告该问题。
What?
https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-mso_win10-mso_2016/excel-2016-vba-bug/b799dfc2-7cef-417d-8a41-96661a360c43 https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-mso_win10-mso_2016/excel-2016-vba-bug/b799dfc2-7cef-417d-8a41-96661a360c43
- 打开 Excel > 文件 > 反馈 > 发送皱眉
- 通过Uservoice - 点击以下链接查看其他人的反馈并提供反馈 -https://excel.uservoice.com/ https://excel.uservoice.com/
这不是对新图标配色方案的建议。这是一个已有 8 年历史的错误,它使 Access 应用程序和带有宏的 Excel 工作表计算出错误的答案(并且它还会阻止迁移到 Office 64,因为我们无法取出代码)。
现在我的问题是:
- 我怎样才能修复这个错误?
- 是否有人拥有令人印象深刻的 SLA 或更好的人脉关系来支持我的请求?
- 有没有办法直接报告VBA错误? (这是因为我们目前怀疑 64 位 VBA 中存在更多错误)
- 我在 uservoice 中做了一份新报告。您认为可以投票通过吗?https://access.uservoice.com/forums/319956-access-desktop-application/suggestions/43660329-fix-this-64-bit-vba-compiler-bug-temporary-object https://access.uservoice.com/forums/319956-access-desktop-application/suggestions/43660329-fix-this-64-bit-vba-compiler-bug-temporary-object
UPDATE: x-发布到
https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-msoffice_custom-mso_2019/invalid-code-by-vba-64-bit-compiler/b91f984a-194c-4453-b8c5-02881afaf83b https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-msoffice_custom-mso_2019/invalid-code-by-vba-64-bit-compiler/b91f984a-194c-4453-b8c5-02881afaf83b
UPDATE 2:
我有机会在 Office 365 for Mac 安装上尝试代码(其中 Win64 定义为true
) and 该错误没有出现在那里。所以现在是PC的事情了。
UPDATE 3:
Post 已发送至 HN 和 The Register:
https://www.theregister.com/2021/08/19/64_bit_microsoft_vba_bug/ https://www.theregister.com/2021/08/19/64_bit_microsoft_vba_bug/
https://news.ycombinator.com/item?id=28188251 https://news.ycombinator.com/item?id=28188251
UPDATE 4:
今天(2021 年 11 月 15 日)刚刚检查了 Office 365 和错误现在已经消失了!看来有人关注了然而,我不知道今年收到的无数累积更新中哪一个成功了,而且还不知道其他 Office 版本是否也得到了修复。