LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 101
Default Screen Off from VBA

Well, it sorta works on the laptop. It does turn the screen off, but it
kicks back on after 1-2 seconds, even if I set it to wait 10-20-30 seconds.
A couple of times it stayed off maybe 4-5 seconds, but other than that, it
basically just kicked right back on.

I had had the same problem on my desktop at work when I just used the code
you posted. But when I substituted a delay routine I use for some other
things, it worked on my desktop for whatever period of time I wanted. But on
the laptop it almost always kicked right back on regardless of the routine I
used.

I can set my macro to send the MONITOR_OFF command each time it runs through
its routine - that will probably work for me. But any ideas as to why it
won't stay turned off?

--
Bill @ UAMS


"PapaDos" wrote:

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



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
print box opens in right screen of dual screen setup why gerrys Excel Discussion (Misc queries) 1 June 30th 06 06:47 PM
How Do I Autofit To Screen Size tweacle Excel Worksheet Functions 3 January 29th 06 08:16 PM
Need to convert point on screen to various screen resolutions Donna YaWanna Excel Discussion (Misc queries) 5 October 26th 05 10:10 PM
Hyperlink Screen Tips not cross platform Randy Klein Excel Discussion (Misc queries) 0 October 12th 05 08:29 AM
How do I move the current cell to the top of the screen? mad.cow Excel Discussion (Misc queries) 6 May 29th 05 05:35 AM


All times are GMT +1. The time now is 10:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"