Excel 2016 Workbook.BeforeClose事件触发每隔一个时间的bug [英] Excel 2016 Workbook.BeforeClose event firing every other time bug

查看:391
本文介绍了Excel 2016 Workbook.BeforeClose事件触发每隔一个时间的bug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

8/25/16更新:我​​更新了Office 2016(现在版本为16.0.7167.2040),似乎已经修复。我没有更改任何加载项或任何东西。也许微软看看这些问题!希望任何有这个问题的人都可以更新他们的版本,看到这个bug已经得到纠正。 (我从OP中删除了收件箱链接。)

8/25/16 Update: I updated Office 2016 (now on v 16.0.7167.2040) and it seems to have been fixed. I didn't change any add-ins or anything. Maybe Microsoft does look at these issues! Hopefully, anyone else with this issue can update their version and see this bug has been corrected. (I removed the dropbox link from the OP.)

4/9/16更新:我​​更新了Office(现在版本为16.0.6729.1012)而不是.beforeclose事件只有一次发射,现在事件每隔一段时间就会触发。这是一个显示奇怪行为的视频: screencast.com/t/BdkTd9ib

4/9/16 Update: I updated Office (now on v 16.0.6729.1012) Instead of the .beforeclose event only firing once, now the event fires every other time. Here is a video showing the odd behavior: screencast.com/t/BdkTd9ib

原始帖子:
在这个bug的今天,.beforeclose事件只在Excel 2016中发生一次。以下代码按照预期在Excel 2007,2010和2013(全部32在Windows 10上的位).beforeclose事件每次触发。它在Excel 2016中无法正常工作。

Original Post: Ran across this bug today where the .beforeclose event only fires one time in Excel 2016. The following code works as expected in Excel 2007, 2010, and 2013 (all 32-bit on Windows 10) where the .beforeclose event fires every time. It does NOT work as expected in Excel 2016.

工作簿中的代码。只能关闭事件才会触发一次。如果用户点击取消到自定义保存对话框,然后单击取消=真,这样工作簿将不会关闭,并且用户再次关闭工作簿,则.BeforeClose不会触发。

Code in the Workbook.BeforeClose event only fires one time. If the user clicks "Cancel" to a custom save dialog box and Cancel=True so the workbook won't close, and the user goes to close the workbook again, the .BeforeClose does not fire. The default Excel close dialog shows instead.

手动复制的步骤:
创建新的.xlsm工作簿。
创建一个名为range的isDirty。
在sheet1模块中放入以下内容:

Steps to reproduce manually: Create new .xlsm workbook. Create a "isDirty" named range. In the sheet1 module put the following:

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target(1) = [isDirty] Then Exit Sub
        Application.EnableEvents = False
        [isDirty] = True
        Application.EnableEvents = True
    End Sub

在ThisWorkook模块中输入:

Input this in the ThisWorkook Module:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    With Application
        .EnableEvents = False
        .DisplayAlerts = False
        .Calculation = xlCalculationManual
    End With

    With Me
        If [isDirty] = True Then
            Select Case MsgBox("Do you want to save the changes you made to '" & .Name & "'?", _
                vbYesNoCancel + vbExclamation, "CUSTOM CLOSE BOX")
            Case Is = vbYes
                Call CustomSave
            Case Is = vbNo
                 Me.Saved = True
            Case Is = vbCancel
                Cancel = True
                GoTo Cleanup
            End Select
        End If
    End With

    With Application
        .EnableEvents = True
        .StatusBar = False
        .ScreenUpdating = True
        .DisplayAlerts = True
    End With

    Me.Saved = True
    Exit Sub

Cleanup: 'user hit cancel to custom save dialog box
    With Application
        .DisplayAlerts = True
        .CalculateBeforeSave = False
        .Calculation = xlCalculationManual
        .EnableEvents = True
        .ScreenUpdating = True
        .StatusBar = False
    End With
    Me.Saved = False
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
     [isDirty] = False
End Sub

插入一个自定义模块并将其放在这里代码:

Insert a custom Module and put this code:

Sub CustomSave()
    [isDirty] = False
    ThisWorkbook.Save
    ThisWorkbook.Saved = True
End Sub

如果用户对Sheet1进行了更改, isDirty标志设置为True。
用户单击X关闭工作簿,然后关闭事件触发,并打开自定义确认关闭对话框。
用户点击取消。

If the user makes a change on Sheet1, the isDirty flag is set to True. User clicks the X to close the workbook and .beforeclose event fires and the custom confirm close dialog box opens. User hits cancel.

用户再次点击X,现在正常的Excel工作簿关闭对话框打开,询问用户是否要保存更改。

User hits X again and now the normal Excel workbook close dialog opens asking if the user wants to save changes. The .beforeclose event does not fire again.

任何建议?

推荐答案

p>更新到最新版本的Office,这不应该是一个问题。几个月,但它是固定的。

Update to the latest version of Office and this shouldn't be an issue any longer. Took a few months but it's fixed.

这篇关于Excel 2016 Workbook.BeforeClose事件触发每隔一个时间的bug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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