maverick
maverick

Reputation: 83

Put Windows 7 to Sleep using VBA

I have some VBA code which takes hours to run. After completion of the code, I want the windows 7 (64 Bit Professional) to go to SLEEP.

What VBA code can I use at the end to achieve this?

Upvotes: 0

Views: 717

Answers (1)

CustodianOfCode
CustodianOfCode

Reputation: 674

Correct me if I'm wrong, but I'm not aware of a way to do this natively in vba. Usually for these sort of things I'll search the internet for a way to do it in the command prompt, then have my vba run a command line script.

Sure enough, here is an explanation of how you can shut down / sleep via command line.

https://superuser.com/questions/42124/how-can-i-put-the-computer-to-sleep-from-command-prompt-run-menu

And you'll find many examples online of running command line scripts from vba which you can use to execute these commands. At it's most basic, something like this:

shell "notepad.exe"

Upvotes: 1

Related Questions