复制表单不闪烁

我想复制一个模板工作表的左侧,由报告生成器填充。 这一切工作正常。

然而,当涉及到表格复制行(如下所示)时,它们就像excel出现时一样闪烁,然后消失 – 尽pipe偶尔我会留下蓝色的,部分填充的excel窗口。

我已经将Application.ScreenUpdating设置为false,并且.Visible也设置为false,并且我每次都重置它们以最小化中断。 这闪光真的很烦人。 有没有办法阻止它?

  ' create new sheet from template sheet shtDeliveryVariance.Copy Before:=shtDeliveryVariance Set shtVariance = Sheets(shtDeliveryVariance.Index - 1) shtVariance.Name = "Delivery Variance " & Format(nSheetNumber, "000") ' minimise the flashes Application.Interactive = False Application.ScreenUpdating = False Application.Visible = False 

更新 :如果我使用Set shtVariance = Sheets.Add我没有得到闪光灯,但我失去了所有漂亮的格式。

也许我误解了,但不应该在复制之前将application.screenupdating设置为false?

更新仍然不完全清楚是什么导致了这个问题,但屏幕闪烁可能是被复制的工作表被激活。 我确实得到了一些屏幕闪烁的工作表,包含一个大的图像使用像你这样的代码。 你可以尝试通过设置Application.EnableEvents = False禁用激活也许是这样的:

 Application.ScreenUpdating = False Application.EnableEvents = False Dim active As Worksheet Set active = ThisWorkbook.ActiveSheet 'or somesuch 'your code here active.Activate Application.EnableEvents = True Application.ScreenUpdating = true 

运行代码时,我只能得到一个“闪存”。

这是当这行代码运行

 Application.Visible = False 

发生这种情况是因为Excel隐藏,桌面暂时显示,然后再次显示Excel。 我会删除该行的代码。

在重新开启屏幕更新之前,我还会检查是否再次select在调用代码时处于活动状态的表单。

 Sub Test_Flash() Dim shtDeliveryVariance As Worksheet Dim i As Integer Application.Interactive = False Application.ScreenUpdating = False Set shtDeliveryVariance = ActiveWorkbook.Worksheets("Sheet1") nSheetNumber = 1 For i = 1 To 100 shtDeliveryVariance.Copy Before:=shtDeliveryVariance Set shtVariance = Sheets(shtDeliveryVariance.Index - 1) shtVariance.Name = "Delivery Variance " & Format(nSheetNumber, "000") nSheetNumber = nSheetNumber + i Next i ActiveWorkbook.Worksheets("Sheet1").Select Application.Interactive = True Application.ScreenUpdating = True End Sub