#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 101
Default Screen Off from VBA

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Screen Off from VBA

I assume that it would be good enough to keep the screen from flashing form
one sheet to the next as the macro executes? If so then just add something
like this to your code...

sub whatever()
Application.screenupdating = false
'your code here
Application.screenupdating = true
end sub
--
HTH...

Jim Thomlinson


"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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 101
Default Screen Off from VBA

I have the updating turned off - I was hoping there was a way to actually
make the screen go blank, such as when a screen saver kicks in. Maybe there
is a way to alter the screen saver parameters in VBA?

--
Bill @ UAMS


"Jim Thomlinson" wrote:

I assume that it would be good enough to keep the screen from flashing form
one sheet to the next as the macro executes? If so then just add something
like this to your code...

sub whatever()
Application.screenupdating = false
'your code here
Application.screenupdating = true
end sub
--
HTH...

Jim Thomlinson


"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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default Screen Off from VBA

The easiest way will be to just flip the screen almost closed and then ignore
it. You might be able to adjust the Screen saver via an API but as a guess it
will not be easy to do and probably will not be worth doing.
--
HTH...

Jim Thomlinson


"BillCPA" wrote:

I have the updating turned off - I was hoping there was a way to actually
make the screen go blank, such as when a screen saver kicks in. Maybe there
is a way to alter the screen saver parameters in VBA?

--
Bill @ UAMS


"Jim Thomlinson" wrote:

I assume that it would be good enough to keep the screen from flashing form
one sheet to the next as the macro executes? If so then just add something
like this to your code...

sub whatever()
Application.screenupdating = false
'your code here
Application.screenupdating = true
end sub
--
HTH...

Jim Thomlinson


"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

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 208
Default Screen Off from VBA

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



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 101
Default Screen Off from VBA

That sounds like what I need. I will try it and let you know what happens.

Thanks!

--
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

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 101
Default Screen Off from VBA

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

  #8   Report Post  
Posted to microsoft.public.excel.misc
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

  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 101
Default Screen Off from VBA

Well, I haven't tried it on my laptop - it is at home. But it worked on my
desktop at work. I'll try the laptop tonight and let you know.

--
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

  #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

Reply
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 12:23 PM.

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

About Us

"It's about Microsoft Excel"