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 ?
 

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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)
 

Watch MrExcel Video

Forum statistics

Threads
1,114,041
Messages
5,545,679
Members
410,697
Latest member
srishtijain0708
Top