当ScreenUpdating = False并创建新的隐藏工作簿时,Excel 2013和2016会闪烁

时间:2016-09-15 18:27:57

标签: excel vba excel-vba winapi excel-2013

如果在Excel 2013或Excel 2016中运行以下代码,则会导致Excel闪烁。

有没有人对如何阻止闪烁有任何建议?

Sub FlickerTestMain()
    Application.ScreenUpdating = False
    Application.EnableEvents = False
    Application.DisplayAlerts = False

    FlickerTestHelper

    Application.ScreenUpdating = True
    Application.EnableEvents = True
    Application.DisplayAlerts = True
End Sub

Sub FlickerTestHelper()
    Dim currentWorkbook As Workbook, newWorkbook As Workbook
    Set currentWorkbook = Application.ActiveWorkbook
    Set newWorkbook = Application.Workbooks.Add(xlWBATWorksheet)
    newWorkbook.Windows(1).Visible = False
    currentWorkbook.Activate
    newWorkbook.Worksheets(1).Range("a1:Z10000").Value2 = "test"
    newWorkbook.Close False
End Sub

0 个答案:

没有答案