Application.ScreenUpdating = False issues

Afro_Cookie

Board Regular
Joined
Mar 17, 2020
Messages
103
Office Version
  1. 365
Platform
  1. Windows
Found this post, ScreenUpdating = False not working, that is having a similar issue to mine. From what I've read this is a common issue with Excel after an update Microsoft did.

Below is my code and I cannot figure out how to keep ScreenUpdating set to false. It's not a major issue but the continual flickering of the screen is really annoying, especially when other workbooks are open as well.

Any help would be appreciated.

VBA Code:
Sub SaveThis()

Application.ScreenUpdating = False
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.DisplayAlerts = True

NextTime = Now + TimeValue("00:00:10")
Application.OnTime NextTime, "SaveThis"

End Sub

Sub SaveThisEnd()
    On Error Resume Next
    Application.ScreenUpdating = False
    Application.OnTime NextTime, "SaveThis", Schedule:=False
End Sub
 
Perfect! Thank you for all your help!!

Ok- I see what you mean .

This is due to the Single Document Interface (SDI) that came with excel 2013 . It can be annoying and counter-intuitive when you are working on a different workbook and then all of a sudden you are taken to the workbook that is running the save code.

Here is a custom Property that I named (EnableSDIWindowActivation) which if you set it to FALSE before saving will solve the issue :

Your code now becomes :
VBA Code:
Option Explicit

#If VBA7 Then
    Declare PtrSafe Function SetWindowPos Lib "user32" (ByVal hwnd As LongPtr, ByVal hWndInsertAfter As LongPtr, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr
#Else
    Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    Declare Function GetActiveWindow Lib "user32" () As Long
#End If


Dim NextTime As Double


Sub SaveThis()

    EnableSDIWindowActivation = False
        ThisWorkbook.Save
    EnableSDIWindowActivation = True
   
    NextTime = Now + TimeValue("00:00:10")
    Application.OnTime NextTime, "SaveThis"

End Sub

Sub SaveThisEnd()
    On Error Resume Next
    Application.OnTime NextTime, "SaveThis", Schedule:=False
End Sub



Public Property Let EnableSDIWindowActivation(ByVal Enable As Boolean)

    Const HWND_TOPMOST = -1
    Const HWND_NOTOPMOST = -2
    Const SWP_NOSIZE = &H1
    Const SWP_NOMOVE = &H2
    Const SWP_NOACTIVATE = &H10

    If Not ActiveWorkbook Is ThisWorkbook Then
        If Enable Then
            SetWindowPos GetActiveWindow, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_NOMOVE Or SWP_NOSIZE
        Else
            SetWindowPos GetActiveWindow, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_NOMOVE Or SWP_NOSIZE
        End If
    End If

End Property
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top