I need some help with Excel VBA (2010 on windows 7). What I'm trying to do is close Excel and then shutdown the pc. The code I have is:
Declare Function ExitWindowsEx& Lib "User32" (ByVal uFlags As Long, ByVal dwReserved AS Long)
Global Const EWX_LOGOFF = 0
Global Const EWX_FORCE = 4
....Main Code Here ....
Application.DisplayAlerts = False
Application.Quit
Action = ExitWindows(EWX_LOGOFF or EWX_FORCE, 0)
Intermittently I get the following error:
Cannot Quit Microsoft Excel
The machine still logs off though, which is what I want so it's not a major issue. I would just like to exit cleanly. I've kept EWX_FORCE as I don't want to be prompted by windows. Any suggestions?