PDA

View Full Version : Seeking help in creating an excel macro for shutting down pc



clickrudra
03-28-2010, 03:01 PM
Hi All

I am not an expert in Excel VBA.

Looking for your help to create a macro in excel which can initiate windows logoff/Shutdown or startup function on specified time

My objective is to Set (enter) time in cell A1 to shutdown or logoff Laptop/PC

please help with this.

Thanks
Rudra

Bob Phillips
03-28-2010, 03:55 PM
See http://vbnet.mvps.org/index.html?code/system/exitwindowsex.htm

clickrudra
03-29-2010, 12:36 AM
Thanks for the link.

I tried inserting a new module and copying and pasting the code mentioned on the webpage.

Tried running also but couldn't run it.

Requesting for your help, please tell me i want to define time in excel sheet cell "A2" (this is the time when i want my laptop to log me off automatically).

Actually i will be keeping the excel workbook/file with macro open which will be logging off Laptop automatically on defined time.

Thanks in advance
Regards
Rudra.

Bob Phillips
03-29-2010, 01:04 AM
Sorry, I am not going to test code which will shutdon my laptop.

The code as presented is for a VB6 form, so it has to be amended. You need to strip out the form and invoke it from a macro, using Application.OnTime.

joms
03-29-2010, 01:44 AM
try this, save your files before running the macro:



Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4

Declare Function ExitWindowsEx Lib "user32" _
(ByVal uFlags As Long, ByVal dwReserved As Long) As Long

Sub ShutDown()
'log off the computer
ExitWindowsEx EWX_FORCE Or EWX_REBOOT, 0
End Sub