Đôi khi chúng ta muốn tắt máy tính để đi ngủ, vậy thì cũng không cần phải xài phần mềm gì cao siêu, dùng VBA cũng được đó, các bạn đã thử chưa?
Mã:
Option Explicit
Declare Function ExitWindowsEx& Lib "user32" _
(ByVal uFlags&, ByVal wReserved&)
'//constants needed to exit Windows
Global Const EWX_LOGOFF = 0
Global Const EWX_SHUTDOWN = 1
Global Const EWX_REBOOT = 2
Global Const EWX_FORCE = 4
'*******************SHUT DOWN*********************
Sub TurnOffXP()
'shutdown.exe will NOT work on Windows 95, 98, 98 SE and ME
'tuhocvba: da test tren Windows 10, van chay binh thuong
ActiveWorkbook.Save
Application.DisplayAlerts = False
Application.Quit
'//shut down the computer
Shell "shutdown -s -t 1200", vbHide 'after 1200s, the computer will shutdown
End Sub