none
How to avoid annoying cursor flickering while executing a long macro? RRS feed

  • Question

  • Hi,

    In my VBA project when long macros are executed there is always an Application.ScreenUpdating = False statement at the beginning and an Application.ScreenUpdating = True at the end; so the user will not see the text being manipulated. And that is OK.

    I notice though an annoying flickering of the mouse pointer probabling due to a changing of his form while the macro is executed. This happens with and without the following statements at the beginning an the end of macros rispectively:  lngOldCursor (my variable) = System.Cursor :   System.Cursor = wdCursorWait and  System.Cursor = lngOldCursor.

    I read that it could be caused by a WindowSelectionChange procedure (which I do have) but it seems is not (I tryed to disabled it, and it seems the same).

    I guess is due to some word statement as Range.PasteAndFormat but I'm not sure.

    Do you have some idea, please?

    Lauro

    Tuesday, April 24, 2012 9:36 PM

Answers

  • Hi Lauro

    <<The help file  says that I could use the range [ expression.Add(Type, Range) ] to add a new CC. And that is true for all others Content Controls but the Group Content Control which need the selection. Why? I could solve that.>>

    Yes, there is no other way to group content controls - it requires a selection.

    There's probably not going to be any way to completely get rid of the flicker, but have you set Application.ScreenUpdating = false? That might help a little...


    Cindy Meister, VSTO/Word MVP

    Wednesday, April 25, 2012 8:30 AM
    Moderator

All replies

  • Hi Lauro,

    If in your macro you are using Selection commands to move thru the document, that invokes screen activity and thus flashing. Instead make use of the Range command, which does not create screen activity while manipulating the document.

    Hope this helps


    Kind Regards, Rich ... http://greatcirclelearning.com

    Wednesday, April 25, 2012 12:59 AM
  • Hi Rich,

    thank you very much for your help.

    It's quite difficult for me to detect the precise situation (the exact line of code) when the flickering of the cursor occurs.

    I tried to disseminate one of my routine with plenty of

    Debug.Print NAME_SUB + BEFORE(AFTER)_STATEMENT & System.Cursor
    
    OR
    
    Sleep 1000

    My Document holds a big table that is grouped by GroupContentControl. Every macro remove and reinsert the CC.

    My System.cursor value is alwayw 2= wdCursorNormal , either I hold the cursor on the button of the ribbon that trigger the macro either I move (after some sleep) the cursor on the table.

    But if I hold the mouse on the margin (the part above the table) of the document the value will be 4 [a value I don't find in the WdCursorType enumeration] just after a Range .select operation. It seems to me that the pointer became little thick down arow as the one you get when you select a column of a table.

    I always tried to avoid selection operation, either for are more slaggish either becase I have a WindowSelectionChange routine. But I couldn't find the way to avoid

       Dim rng As Range, OldSelection As Range
       Dim objCC As ContentControl
     
    ... 
       Set OldSelection = Selection.Range
       Set rng = MyTable.Range
       rng.MoveStart wdParagraph, -1
       rng.MoveEnd wdParagraph, 1
       rng.Select
       Set objCC = ActiveDocument.ContentControls.ADD(wdContentControlGroup)
       With objCC
          .tag = MYTAG
          .LockContentControl = True
       End With
       Selection.SetRange OldSelection.Start, OldSelection.End
    ...

    when I have to block again the entire table.

    The help file  says that I could use the range [ expression.Add(Type, Range) ] to add a new CC. And that is true for all others Content Controls but the Group Content Control which need the selection. Why? I could solve that.

    Thank you for any further assistance, Lauro

    Wednesday, April 25, 2012 7:35 AM
  • Hi Lauro

    <<The help file  says that I could use the range [ expression.Add(Type, Range) ] to add a new CC. And that is true for all others Content Controls but the Group Content Control which need the selection. Why? I could solve that.>>

    Yes, there is no other way to group content controls - it requires a selection.

    There's probably not going to be any way to completely get rid of the flicker, but have you set Application.ScreenUpdating = false? That might help a little...


    Cindy Meister, VSTO/Word MVP

    Wednesday, April 25, 2012 8:30 AM
    Moderator
  • Yes. That save me to see the manipulation on the page, but not the changing of type of the pointer.

    Thanks anyway, Cindy

    Wednesday, April 25, 2012 10:46 AM
  • Yes. That save me to see the manipulation on the page, but not the changing of type of the pointer.

    Hi Lauro

    And if you explicitly set the cursor to wdCursorWait at the start and change it back to wdCursorNormal at the end of your routine does that help at all?


    Cindy Meister, VSTO/Word MVP

    Wednesday, April 25, 2012 4:59 PM
    Moderator
  • Hi Lauro,

    Another potential way to deal with this, though it depends on the user interface that you require, is to place your long running macros in a user form. The user form becomes the launching mechanism for your macro and also a progress reporting method to the end-user.

    Before starting the long running macro, minimize all open screens and leave screen updating on.  The form stays on the screen and based on some criteria you update it with a message and issue a userform1.repaint command.

    When done, reset the active window and close the form.


    Kind Regards, Rich ... http://greatcirclelearning.com

    Wednesday, April 25, 2012 8:20 PM
  • Hi Cindy!

    Long time no read :-)


    Kind Regards, Rich ... http://greatcirclelearning.com

    Wednesday, April 25, 2012 8:44 PM
  • Hi Cindy, Hi Rich,

    Thanks for yours, as always, fast and kind answers.

    I do set explicitly the cursor to wdCursorWait at the start and change it back at the end of my macro (maybe it's not necessary to change it back - because Word does it by itself at the exit of the procedure), BUT I can't avoid that continuos fast changing of the cursor from one type to another (wdCursorWait & wdCursorNormal ? ).

    It's hard for me to detect the exact line that cause the changing in my real macro and in simulate simpler ones seems there is not problems. (it seems also because I heve often to add a lot of delay to see something in the screeen).

    Lauro

    Sunday, April 29, 2012 1:45 PM
  • Hi Lauro

    Short of perhaps taking control of the screen display using the Windows API, I don't think there's anything you can do.


    Cindy Meister, VSTO/Word MVP

    Monday, April 30, 2012 11:41 AM
    Moderator
  • Thanks again Cindy,

    I think that for the moment I will stay with that flickering, too bad...

    Lauro

    Monday, April 30, 2012 2:21 PM