View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.misc
PapaDos PapaDos is offline
external usenet poster
 
Posts: 208
Default Screen Off from VBA

I found them in the MSDN documentation for Visual Studio, but they are well
published all over the web...

Is your screen really turning off ?
On my laptops, the best I can manage is to put it in standby mode, even when
I use the MONITOR_OFF command...

--
Regards,
Luc.

"Festina Lente"


"BillCPA" wrote:

Worked like a charm!

The hex codes you show for SC_MONITORPOWER, WM_SYSCOMMAND, etc. - where can
those be found?

--
Bill @ UAMS


"PapaDos" wrote:

You can try something based on this code, but it will probably only put the
screen in "Standby" mode...

The sub turns the monitor OFF and ON again 30 seconds later...


Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam
As Any) As Long

Sub setMonitor()
Const SC_MONITORPOWER As Long = &HF170&
Const WM_SYSCOMMAND As Long = &H112&
Const MONITOR_ON As Long = -1&
Const MONITOR_OFF As Long = 2&
Const MONITOR_STANDBY As Long = 1&
Const delay As String = "0:00:30"

Debug.Print
On Error GoTo bye
Debug.Print Now, "MONITOR OFF"
SendMessage Application.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF
Application.Wait (Now + TimeValue(delay))

' Debug.Print Now, "MONITOR ON"
' SendMessage application.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON
' Application.Wait (Now + TimeValue(delay))

' Debug.Print Now, "MONITOR IN STANDBY"
' SendMessage Application.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER,
MONITOR_STANDBY
' Application.Wait (Now + TimeValue(delay))

bye:
SendMessage Application.hWnd, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_ON
Debug.Print Now, "MONITOR ON"
End Sub

--
Regards,
Luc.

"Festina Lente"


"BillCPA" wrote:

I have an analysis macro I run every now and then that runs anywhere from 2-6
hours. If I run it on my desktop, I turn my monitor off while it runs. Is
there some way in VBA to turn off the screen on a laptop while the macro
executes?

--
Bill @ UAMS