Shut down a computer from within vba

drom

Active Member
Joined
Mar 20, 2005
Messages
477
Office Version
  1. 2019
  2. 2016
  3. 2013
  4. 2011
  5. 2010
  6. 2007

hi and many thanks in advance!



is there a way to shut down a computer from within vba

to quit excel we use:

Code:
Application.Quit

1) to quit a computer?

thanks!
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Tazguy37

MrExcel MVP
Joined
May 28, 2004
Messages
4,237
How about this?:

Code:
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish
'
Private Declare Function apiExitWindowsEx Lib "user32" _
        Alias "ExitWindowsEx" _
        (ByVal uFlags As Long, ByVal dwReserved As Long) _
        As Long

Public Const EWX_FORCE = 4      'Forcibly terminates processes
                                'that do not respond.
Public Const EWX_LOGOFF = 0     'Terminates processes, then logs off.
Public Const EWX_SHUTDOWN = 1   'Powers the system off, if possible.
Public Const EWX_REBOOT = 2     'Reboots the system.

Function fTerminateWin(lngExitVal As Long)
    fTerminateWin = apiExitWindowsEx(lngExitVal, 0)
End Function

Sub test()
    fTerminateWin (4)           'Only 4 and 0 work on my machine
End Sub

HTH
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,627
Messages
5,832,758
Members
430,165
Latest member
Idjaz

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top