title: VBA - How to use ShellExecute?
body: <p>I'm trying to  get the computer to sleep through excel VBA. For that to happen I need to disable hybernation which can only be done with elevated permissions. So I'm trying ShellExecute - following Microsoft's instructions on <a href="https://support.microsoft.com/en-us/kb/170918" rel="nofollow">this page</a>, but I'm getting an runtime error ('49' Bad DLL calling convention).</p>
  
  <p>Edit:
  Changed the code and it works now, but the parameters are incorrect.</p>
  
  <pre class="lang-vb prettyprint-override"><code>Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
                                                               ByVal hwnd As Long, _
                                                               ByVal lpszOp As String, _
                                                               ByVal lpszFile As String, _
                                                               ByVal lpszParams As String, _
                                                               ByVal lpszDir As String, _
                                                               ByVal FsShowCmd As Long) as long
  Const SW_SHOWNORMAL as long = 1
  Sub DoSleep()
      ShellExecute 0, "runas", "C:\WINDOWS\System32\rundll32.exe", "powercfg -h off", "C:\", SW_SHOWNORMAL
      Shell "C:\WINDOWS\System32\rundll32.exe powrprof.dll,SetSuspendState 0,1,0"
      ShellExecute 0, "runas", "C:\WINDOWS\System32\rundll32.exe", "powercfg -h on", "C:\", SW_SHOWNORMAL
  End Sub
  </code></pre>