I'm looking for a way to put my notebook [Win7] into hibernation via VBA [Excel 2010]. I was searching for a solution but couldnt find a handy one.
I was playing with the SendKeys
method but no luck. Then the Shell "C:\WINDOWS\System32\rundll32.exe powrprof.dll,SetSuspendState", vbHide
gave me Compile error: Invalid outside procedure
message. The Function ExitWindowsEx
gives only the choices to log off, shut down and reboot but no hibernation as far as I know. Thank you for your help in advance.
I've just successfully hibernated my comp. Here is the magnificent code:
Option Explicit
Declare Function SetSuspendState Lib "powrprof.dll" _
(ByVal Hibernate As Boolean, ByVal ForceCritical As Boolean, ByVal DisableWakeEvent As Boolean) As Boolean
Sub Yoo()
Dim value_hibernate As Integer
value_hibernate = SetSuspendState(True, False, False)
If value_hibernate <> 1 Then MsgBox "Hibernation has failed."
End Sub
Some comments said that its better going with the SetSuspendState
than the PowerState one.
Have fun hibernating your machines via VBA! Yaay!