Shut Down the Computer

hmk

Active Member
Joined
Jun 8, 2004
Messages
423
Hi there

Is there a VBA code to shut down the computer ?
 

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

Legacy 98055

Guest
A one liner:

CreateObject("Shell.Application").ShutdownWindows
 

Emily

Active Member
Joined
Aug 28, 2002
Messages
304
A one liner:

CreateObject("Shell.Application").ShutdownWindows

Hi,

It's only pop up the shutdown window

Can it shutdown automatically?
 

hmk

Active Member
Joined
Jun 8, 2004
Messages
423

ADVERTISEMENT

Thank u 4 reply

i tried this
Code:
Sub Test2()

'SHUTDOWN [logoff_option]  [/m \\Computer] [options]
'/s         Shutdown    
'/r         Shutdown and Restart

SHUTDOWN /s 

End Sub

but it tells me Expected : Expression and highlight this sign /

could you please show me how to make it work ?? (y)
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,958
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Perhaps:

Code:
Sub test()
Shell (Environ("SystemRoot") & "\System32\shutdown.exe -s")
End Sub
 

hmk

Active Member
Joined
Jun 8, 2004
Messages
423
Thank u v much

it worked, but how about using r, it did not work, it only shuts the pc down, any idea why ?

and how about controlling the defult time of shuting down ?


r is to shutdown and restart the PC

Thank u v much (y)
 

Forum statistics

Threads
1,141,665
Messages
5,707,707
Members
421,524
Latest member
Bharath99

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