ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to run a scheduled macro and Log Off system??? (https://www.excelbanter.com/excel-programming/295335-how-run-scheduled-macro-log-off-system.html)

Jules[_4_]

How to run a scheduled macro and Log Off system???
 
Hello All,
If anyone can help me I would be eternally grateful. I am running a scheduled task of opening an excel spreadsheet and running an auto macro at a specific time every night in Windows NT. Does anyone know how(or if) I can have that macro, or another, close out the excel program and log off my profile on the computer. Right now I have to leave myself logged in and the task leaves Excel open when it is finished. I tried to put my username and password in the appropriate boxes when I am prompted for it in Task Scheduler, but it doesn't work unless I am logged in. My IT person advises that I can't leave my computer logged on continuously without logging it off periodically. Any suggestions?

TH[_3_]

How to run a scheduled macro and Log Off system???
 
You can quit Excel with this command: Application.quit

Before quitting be sure to save the workbook. I'm doing the same thing you
are and also have some code in the ThisWorkbook BeforeClose event. If you
get prompts showing up there, you'll need to do something to recognize this
is an auto close command and bypass the save dialog box if it shows up. I'm
hoping the .save command below does this for you. Here's my code in my timer
routine. Some of it my not be necessary, but it definitely works:

If FinalTimerDone Then 'Recognizes you want to quit
Application.DisplayAlerts = False 'Stops Save message I think
AutoQuit = True
'My Public variable to recognize AutoQuit in BeforeClose event
ThisWorkbook.Save
Application.Quit
End If

This is code from my Before_Close event if needed:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
StopTimer 'Stops current timer. Not needed if quitting Excel
If AutoQuit Then
Application.DisplayAlerts = False
else
'Do something different on normal quit if desired
End If
End Sub


So, I'm not really sure if the DisplayAlerts = False are necessary, but
they're in my code and it's working and I'm sure no harm is done by using
them.

TH

On 4/16/04 11:56, in article
, "Jules"
wrote:

Hello All,
If anyone can help me I would be eternally grateful. I am running a
scheduled task of opening an excel spreadsheet and running an auto macro at a
specific time every night in Windows NT. Does anyone know how(or if) I can
have that macro, or another, close out the excel program and log off my
profile on the computer. Right now I have to leave myself logged in and the
task leaves Excel open when it is finished. I tried to put my username and
password in the appropriate boxes when I am prompted for it in Task Scheduler,
but it doesn't work unless I am logged in. My IT person advises that I can't
leave my computer logged on continuously without logging it off periodically.
Any suggestions?




All times are GMT +1. The time now is 01:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com