excel - 如何修复这个有 8 年历史的 VBA 64 位编译器错误?

标签 excel vba ms-access 64-bit

所以这是错误:在 64 位 VBA 主机(例如 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 位 VBA 主机并在即时窗口中运行“测试”,出现预期的结果:
False
False
但是,如果您使用的是 64 位 VBA主机,然后就出来了:
False
True
除非,当您删除或重命名 Class_Terminate() sub,在这种情况下会出现正确的输出。
我已经将错误跟踪到这个最小的示例。显然,问题似乎在于,使用临时对象(此处为 new SomeClass)会破坏对 IF 的评估。不知何故,使条件的值看起来是 True没关系。
好的,这是一个严重的错误,因为 64 位编译器是疯狂的,所有 IF有麻烦了。
全部 IF ? WHILE 呢? ?
While ReturnFalse(New SomeClass)
 Debug.Print "Oh no!"
Wend
是的,WHILE也有麻烦,因为这会打印“哦,不!”在一个循环中。
这很麻烦,我可以在任何地方重现它:
  • Microsoft® Access® für Microsoft 365 MSO (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 当然。
    摘要:我可以在我拥有的所有版本的 Office 中找到这个错误,从 2013 年开始,它可能至少有 8 年的历史。
    好的,这个错误之前是否影响过其他人?是的:
    去年的这个帖子:
    VBA takes wrong branch at If-statement - severe compiler bug?
    2018 年 10 月在 excel.uservoice.com(显然是微软的用户意见箱之类的)中的这篇帖子:
    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

    If, after testing with others, the code fails and it really shouldn't, you can report the issue directly to Microsoft using the Smile button in Excel.


    什么?
    https://answers.microsoft.com/en-us/msoffice/forum/msoffice_excel-mso_win10-mso_2016/excel-2016-vba-bug/b799dfc2-7cef-417d-8a41-96661a360c43
    1. Open Excel > File > Feedback > Send a Frown
    2. Through Uservoice - Click the following link to see the feedback of others and to provide feedback - https://excel.uservoice.com/

    这不是对新图标配色方案的建议。这是一个已有 8 年历史的错误,它使 Access 应用程序和带有宏的 Excel 工作表计算出错误的答案(并且它还阻止了此处向 Office 64 的迁移,因为我们无法获取我们的代码)。
    现在这是我的问题:
  • 我怎样才能修复这个错误?
  • 是否有人会支持我的请求?
  • 有没有办法直接报告 VBA 错误? (这是因为我们目前怀疑 64 位 VBA 中存在更多错误)
  • 我在 uservoice 中做了一个新的报告。你认为它可以被投票吗? https://access.uservoice.com/forums/319956-access-desktop-application/suggestions/43660329-fix-this-64-bit-vba-compiler-bug-temporary-object

  • 更新 : 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
    更新 2 :
    我有机会在 Office 365 for Mac 安装(其中 Win64 定义为 true )上尝试代码,并且错误没有出现在那里。所以现在是PC的事情。
    更新 3 :
    邮寄到 HN 和 The Register:
    https://www.theregister.com/2021/08/19/64_bit_microsoft_vba_bug/
    https://news.ycombinator.com/item?id=28188251
    更新 4 :
    今天(2021 年 11 月 15 日)刚刚检查了 Office 365 和 错误已消失 !看来有人关注了。但是,我无法弄清楚,我今年收到的大量累积更新中的哪一个起到了作用,但还不知道其他 Office 版本是否也已修复。

    最佳答案

    Sub Test()
        Debug.Print ReturnFalse(New SomeClass)
    
        If ReturnFalse(New SomeClass) Then
            Debug.Print True
        Else
            Debug.Print False
        End If
        
        If True = ReturnFalse(New SomeClass) Then
            Debug.Print True
        Else
            Debug.Print False
        End If
    End Sub
    
    退货
    False
    True
    False
    
    所以If True = ReturnFalse(New SomeClass) Then修复它
    对于循环,这也修复了它
    Do While True = ReturnFalse(New SomeClass)
        Debug.Print "Oh no!"
        Exit Do
    Loop
    

    强烈推荐评论使用上面的解决方法,所以没有人删除 True =将来(例如,因为他以 32 位开发,甚至没有遇到问题)。
    ' Don't remove `True =` due to a compiler bug in x64 the condition would always be true. 
    ' See https://stackoverflow.com/questions/68034271/how-can-i-get-this-8-year-old-vba-64-bit-compiler-bug-fixed
    If True = ReturnFalse(New SomeClass) Then
    
    If ReturnFalse(New SomeClass) And False = True Then将是 True有了这个错误。

    关于excel - 如何修复这个有 8 年历史的 VBA 64 位编译器错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68034271/

    相关文章:

    excel - 具有重复名称的形状的 Application.Caller

    excel - 返回字符串中第 N 个字符之后的字符

    excel - 调用用户窗体并返回值

    php - 将Access DB从PC版改为Web版

    java - 尝试更新 Access 数据库时出现 NonWritableChannelException

    ms-access - Showplan.out 在安装了 MS-Access 2003 和多个版本的 Office 的 Windows 7 中?

    vba - 无法从 .vbs 文件执行宏

    excel - 如何逐个复制列并在每次复制之间执行计算?

    excel - 创建 VBA 宏以计算具有多个条件的唯一值计数

    xml - 使用 VBA 提交 Soap XML