tags:

views:

185

answers:

2

I would like to copy a template sheet to the left of itself to be populated by a report generator. This all works fine.

However when it comes to the sheet copying line (shown below) their is a flash as excel appears and then disappears - though occasionally I am left with a blue, partially filled in excel window.

I already have Application.ScreenUpdating set to false and .Visible is also set to false, and I reset them everytime to minimise the disruption. This flash is really annoying. Is there anyway of preventing it?

        ' 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

Update: If I use Set shtVariance = Sheets.Add I don't get the flash, but I lose all the pretty formatting.

+1  A: 

maybe I've misunderstood but shouldn't you have application.screenupdating set to false before copying?

Update Still not entirely clear on what is causing the problem but the screen flicker could be down to the copied worksheet being activated. I did get some screen flicker with a worksheet containing a large image using code like yours. You could try to disable the activation by setting Application.EnableEvents = False Maybe something like this:

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
andyb
I said: I've already set ScreenUpdating to false. I set it again to remove the ugly blue window that is left, but I still have that flicker.
graham.reeds
Ok I misunderstood :)Sorry, cannot reproduce the behaviour (no screen flickering) when using above code. Presumably the template is pretty hefty and the copy operation takes significant time?I don't usually bother with application.visible or application.interactive, application.screenupdating is usually enough. Are you using these for a particular reason?Might help if you give a bit more context and code for this problem.
andyb
Here's some context: We create reports for various groups within and external to our company. These reports are excel xlt files which have vb code modules. The reports in some cases are growing beyond the 65K row limit for excel<=2K3, so we are now splitting across sheets to compensate. The 'template page' is simply a sheet with the prettifying (logo, bit of text, all in the top 7 rows) on it. The code around that section fills in some text before running off to the db to start sucking down the data to fill the report.
graham.reeds
A: 

I could only get a single 'flash' when running your code.

This is when the code in this line is run

Application.Visible = False

This happens because Excel is hidden, the desktop is displayed momentarily and then Excel is displayed again. I would remove that line of code.

I would also check to see that the sheet that was active when the code was called is selected again before turning the screen updating back on.

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
Robert Mearns