skip to Main Content

The suite is triggered by a button on Sheet1 of DrillDown.xlsm.

The suite uses the following workbooks: wbIn, wbOut, wbTarget. The contents of wbIn are used to identify which workbook file should be opened as wbTarget. The relevant rows are then copied from wbTarget to wbOut. During a run of the suite there may be from 1 to 4 wbTargets used. Each one is closed before the next one is opened.

During the execution of the suite there will be between two and five file open events (wbIn and up to four wbTargets). At each of these, Sheet1 of DrillDown.xlsm disappears from view and is replaced by a grey screen. This is followed by a brief re-display of Sheet1 before it again is removed and replaced by the grey screen.

Any thoughts on what I can do to hold focus on Sheet1 of DrillDown.xlsm throughout the entire run of the suite?

I have trawled the net and as a result I have done the following:

Application.ScreenUpdating = False is set.

There is no use of Activate anywhere in the suite. There is no use of Select anywhere in the suite.

The code which opens the target workbook is as below

Set wbTgt = Workbooks.Open(Filename:=sTargetWbk, ReadOnly:=True)  
Set wsTgt = wbTgt.Sheets(1)  

Updated at 13:52 GMT+1 on 31-07-2019

In what follows, “Main Screen” is the content of Sheet1 of ThisWorkbook. If I can work out how big an image file should be, and how to add one, I will let you all see what the “grey screen” looks like. The sequence of events, after accepting the user’s input is as follows:
Main Screen with Hour-glass mouse pointer – no immediate flicker
Flicker to Grey Screen with steady Hour-glass
Hour-glass changes to small White Cross steady
Back to Hour-glass which flickers steadily
Main Screen flashes up very briefly
Then repeat three more times (because I used all four target files on this test) from Flicker to Grey Screen…

By providing these details about the mouse pointer behaviour and the screens displayed, however briefly, I’m hoping somebody out there can get an understanding of what is going on “under the covers” of Excel. All my mouse pointer settings are as factory-shipped.

Updated at 1422 GMT+1

Here’s the Grey Screen image. It was captured by “Print Screen” and then taken into Photoshop to downsize it to fit the web page. I hope!
Grey Screen

2

Answers


  1. Chosen as BEST ANSWER

    Problem SOLVED!

    I added a ThisWorkbook.Activate statement immediately prior to the Set wbTarget =... statement. Now the focus remains on the main worksheet.

    My inspiration came from further Google searches around the subjects of Excel Window Focus Hold in combination with other terms I had used. No single search result gave me the answer. It was more a case of a slow dawning that Activate, along with everything else it did, set the focus on the Excel window specified.

    I never expected to be the one who contribute the solution to his own problem on my very first posting to this forum. The encouragement you guys gave me kept me going until the end.

    Thanks!


  2. I am not sure if there is any easy way to prevent the problem you are describing – I am guessing you are seeing the various workbooks being opened on top of the current one, although I can’t recall having experienced anything quite similar despite at times working with quite big workbooks and macros.

    I wrote the macros you can see below in an attempt to replicate your problem, but didn’t see it – of course there is a lot less work done in the various workbooks in my example than in what you describe, so maybe some of the problems come from that. I tried running the macro both with and without the settings in the bottommost macros turned off, but nothing seemed to replicate your problem.

    Option Explicit
    
    Sub test1()
        Call speedup
    
        Call test2
    
        Call slowdown
    End Sub
    
    Private Sub test2()
        Dim i As Long
    
        For i = 1 To 4
            With Workbooks.Open(Filename:="C:UsersEirikDaudeDesktopTestTest" & CStr(i) & ".xlsx", ReadOnly:=True)
                Application.Wait (Now + TimeValue("0:00:03"))
                Debug.Print .FullName
                .Close
            End With
        Next i
    End Sub
    
    Private Sub speedup()
        Application.EnableEvents = False
        Application.ScreenUpdating = False
        Application.DisplayStatusBar = False
        Application.EnableAnimations = False
        Application.Calculation = xlCalculationManual
    End Sub
    
    Private Sub slowdown()
        Application.EnableEvents = True
        Application.ScreenUpdating = True
        Application.DisplayStatusBar = True
        Application.EnableAnimations = True
        Application.Calculation = xlCalculationAutomatic
    End Sub
    

    As you can see, I am turning off some Excel settings, similarly to what you found when you googled. Contrary to the suggestions in the comments on your question, I recommend only doing this in the main sub you are calling the others from, in order to keep track of which ones are turned off and which ones are turned on. Of course you may need to e.g. calculate some formulas in your sheet in the middle of your code execution, but if you do I would recommend doing so “manually” using Application.Calculate or Application.CalculateFull. I’ll leave it as an exercise to you to figure out what the different settings do, it should be easy enough to google them.

    As you may have guessed already, I think the best recipe for minimizing the amount of grey screen you see is making your code more efficient. Playing around with the settings shown in my macros could be a start, otherwise there are a lot of sites out there making recommendations on how to achieve this (I like this one, for instance). From what you wrote, doing something like wb1.worksheet.range.value = wb2.worksheet.range.value instead of copying the same might be a good place to start. Of course, without knowing exactly what your macro looks like, or what it does, it is hard to offer much concrete advice. I hope this at least could be of some help, I’m sorry I couldn’t be more helpful with the concrete problem you are facing.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search