Consulting

Results 1 to 8 of 8

Thread: Restart my computer

  1. #1
    VBAX Regular
    Joined
    May 2017
    Location
    Dunedin, Otago
    Posts
    11
    Location

    Restart my computer

    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?

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Regular
    Joined
    May 2017
    Location
    Dunedin, Otago
    Posts
    11
    Location
    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

  4. #4
    Add a line of code to save the document before you close it.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location






    Sorry. BTDT meself.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  6. #6
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    266
    Location
    Works great!

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

  7. #7
    VBAX Expert Logit's Avatar
    Joined
    Sep 2016
    Posts
    613
    Location
    SamT:

    "BTDT" <--- ????




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

  8. #8
    VBAX Tutor
    Joined
    Jul 2016
    Posts
    266
    Location
    LOL I had to google it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •