Logout of windows when your macro is complete

There are some occasions where it is nice to have a remote machine run an extended macro and sign out of the computer when the code has finished running. In this case we recommend the following lines of code:

Shell “shutdown -l -t 02”, vbHide                      ‘begins logoff process

Application.Quit                                                       ‘quit excel without question

These two lines will both start the logoff process in windows but also close excel (or any other office product the code is embedded inside of).  In some cases you may wish to save the file prior to closure.  We suggest doing so prior to the first shell line above to avoid logging off during a save.


One response

5 06 2014

Hi, Nice and simplest method. Does this also force shutdown if any application does not allow to proceed with shutdown.

In this case, the VBA code explained in my blog (search for shutdown) might help to Force Shutdown or Logoff.

But still I have to admit that the method explained here in VBAninja is the simplest one.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: