PDA

View Full Version : [SOLVED:] Restart my computer



Jack Brown
06-06-2017, 04:41 PM
Hello
I have this code to restart a computer:
***********************************
Sub TurnOffPC()
Dim Action As Long
Application.DisplayAlerts = False
Action = ExitWindowsEx(EWX_SHUTDOWN, 0&)
Application.Quit
End Sub

***********************************
How do I assign it to a command button:think:?

SamT
06-06-2017, 04:56 PM
With Worksheet Forms Command buttons, Assign sub TurnOffPC() as the Macro. Note that sub TurnOffPC() must be in a standard Module

With Worksheet Control Toolbox (and VBA UserForms) Command Buttons, copy the contents of the sub TurnOffPC() into the CommandButton_Click sub. Note that the CommandButton_Click sub is in the Worksheet Module.

Jack Brown
06-06-2017, 05:19 PM
Thank you!
I did that, and changed "Action = ExitWindowsEx(EWX_SHUTDOWN, 0&)" to "Shell "shutdown -r -f -t 02", vbHide "
Worked perfectly- lost the document I put the button on :)

gmayor
06-06-2017, 08:26 PM
Add a line of code to save the document before you close it.

SamT
06-06-2017, 09:04 PM
:funnyashe





Sorry. BTDT meself.

Kilroy
06-09-2017, 06:59 AM
Works great!


Sub TurnOffPC()
Dim Action As Long
Application.DisplayAlerts = False
Shell "shutdown -r -f -t 02", vbHide
ActiveDocument.Save
Application.Quit
End Sub

Logit
06-09-2017, 07:16 AM
SamT:

"BTDT" <--- ????

:think:


NEVERMIND .... my old brain just engaged gears.

Kilroy
06-09-2017, 08:52 AM
LOL I had to google it.