Lesson#187: VBA program to shutdown PC

Lesson#187: VBA program to shutdown PC
  1. Go to the Developer Tab in Excel. If you haven’t activated the Developer Tab then see here how to do it.
  2. Insert a Command Button by clicking on ‘Insert’.
  3. Create a button on the sheet and double-click to enter the code.

Here is an example of a VBA program that you can use to shut down a Windows PC when a button is clicked:

Private Sub cmdShutdown_Click()
 
  ' Shut down the PC
  Shell "shutdown -s -t 0"
 
End Sub

This program uses the Shell function to execute the shutdown command with the -s and -t 0 arguments. The -s the argument specifies that the PC should be shut down, and the -t 0 argument indicates that the operation should be carried out immediately.

To use this program, create a button on a worksheet and assign this code to the button’s Click event. When you click the button, it will shut down the PC.

Keep in mind that this program should be used with caution, as shutting down the PC can result in data loss or corruption if the PC is not shut down properly. It’s always a good idea to save your work and close all open programs before shutting down the PC.

See also  Lesson#120: What is Input Box in VBA?

Hi! I am Puspendu. I am the founder and author of Excelabcd. I am little creative person, blogger and Excel-maniac guy. I hope you enjoy my blog.

Leave a Reply

Your email address will not be published. Required fields are marked *

*