Disabling Screensaver

  • Thread starter Thread starter Jeff Armstrong
  • Start date Start date
J

Jeff Armstrong

This might be a little far fetched but I would like to
know how if it is possible to make my VBA program disable
the windows screensaver at the beginning of execution and
then enable it at the end. The reason is that the program
seems to error out when the screensaver comes on.

Jeff
 
This nice little API function from Don Bradner seems to do the trick:

Private Declare Function SystemParametersInfo Lib "user32" Alias _
"SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, _
lpvParam As Any, ByVal fuWinIni As Long) As Long

Sub SetScreenSaver(OnOff As Long)
'From Don Bradner
Dim templong As Long
Const SPI_SETSCREENSAVEACTIVE = 17
Const SPIF_UPDATEINIFILE = 1
Const SPIF_SENDWININICHANGE = 2
templong = SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, OnOff, ByVal
0&, _
SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
End Sub

Sub MySub()
SetScreenSaver 0
'your code here
SetScreenSaver 1
End Sub
 
Back
Top