Dazu soll das u.g. Windows API eigentlich dienen.
Ich laufe in EXCEL 2016 auf WIN10 Version 22H2.
Ich rufe meine Funktion 'SystemKeepAwake' im Takt von ca 10s, alle unten gezeigten Parameter-Konstellationen sind aber effektfrei.
Private Declare Sub SetThreadExecutionState Lib "kernel32.dll" (ByRef esFlags As EXECUTION_STATE)
' Parameter usage:
' check https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate
Private Enum EXECUTION_STATE
ES_SYSTEM_REQUIRED = &H1
ES_DISPLAY_REQUIRED = &H2
ES_USER_PRESENT = &H4
ES_AWAYMODE_REQUIRED = &H40&
es_continuous = &H80000000
End Enum
' ist eigentlich ne SUB. So wird verhindert, dass sie direkt in der Liste der ausführbaren Makros erscheint!
Public Function SystemKeepAwake()
' NO EFFECT
Call SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED Or _
EXECUTION_STATE.ES_DISPLAY_REQUIRED Or _
EXECUTION_STATE.es_continuous)
' NO EFFECT
' Call SetThreadExecutionState(EXECUTION_STATE.ES_SYSTEM_REQUIRED Or _
' EXECUTION_STATE.ES_DISPLAY_REQUIRED Or _
' EXECUTION_STATE.ES_USER_PRESENT Or _ == geht nicht, siehe obigen Doku-Link!
' EXECUTION_STATE.ES_CONTINUOUS)
' NO EFFECT
' Call SetThreadExecutionState(EXECUTION_STATE.es_system_required Or _
' EXECUTION_STATE.ES_DISPLAY_REQUIRED Or _
' EXECUTION_STATE.ES_AWAYMODE_REQUIRED Or _
' EXECUTION_STATE.es_continuous)
' Dim l_state As LongPtr
' NO EFFECT
' l_state = EXECUTION_STATE.es_system_required Or _
' EXECUTION_STATE.ES_DISPLAY_REQUIRED Or _
' EXECUTION_STATE.es_continuous
' NO EFFECT
' l_state = EXECUTION_STATE.ES_SYSTEM_REQUIRED Or _
' EXECUTION_STATE.ES_DISPLAY_REQUIRED Or _
' EXECUTION_STATE.ES_AWAYMODE_REQUIRED Or _
' EXECUTION_STATE.ES_CONTINUOUS
' Call SetThreadExecutionState(l_state)
End Function
' ist eigentlich ne SUB. So wird verhindert, dass sie direkt in der Liste der ausführbaren Makros erscheint!
Public Function SystemToStandard()
Call SetThreadExecutionState(EXECUTION_STATE.es_continuous)
End Function