Windows Server 2008 R2 64 bit with Office 2010 Professional Plus 32 bit with SP2
I have a VB script that queries AD for inactive accounts, creates an html email and an Excel spreadsheet, attaches the spreadsheet to the email and sends the report. Everything runs perfect when running it as the service account from a command line.
But when running it as a Schduled Task (as the same service account), it hangs at saving the Excel file. I've tried many different forms of the SaveAs method but they all hang. Here is the part where I save it:
If iLL > 4 Then Addlog oLogFile, "Saving Excel file: " & sExcelFile 'oWorkbook.SaveAs(sExcelFile) <-- commented out, trying different methods oExcel.ActiveWorkbook.SaveAs sExcelFile, 51 If Err.Number <> 0 Then sTemp = "Error saving Excel workbook: " & sExcelFile & " - " & Err.Description Err.Clear Addlog oLogFile, sTemp sError = sError & TimeStamp(sTemp) & "<br />" & vbCRLF End If If iLL > 4 Then Addlog oLogFile, "Closing Excel workbook..." oExcel.ActiveWorkbook.Close If iLL > 4 Then Addlog oLogFile, "Quitting Excel..."
oExcel.Application.Quit
And the log file entry, it never hits the Error block and never hits the "Closing Excel workbook..." part. This is the last 4 lines of the log:
9/5/2013 11:21:36 AM, Setting header row to bold...
9/5/2013 11:21:36 AM, Setting columns to Autofit...
9/5/2013 11:21:36 AM, Sorting by Displayname...
9/5/2013 11:21:36 AM, Saving Excel file: C:\Scripts\InactiveAccounts\data\InactiveAccountReport-20130905.xlsx
And the EXCEL process remains running under the service account.
But when running it from command line under the same account, it runs fine. This is the log after running from the command line:
9/5/2013 11:25:48 AM, Setting header row to bold...
9/5/2013 11:25:48 AM, Setting columns to Autofit...
9/5/2013 11:25:48 AM, Sorting by Displayname...
9/5/2013 11:25:48 AM, Saving Excel file: C:\Scripts\InactiveAccounts\data\InactiveAccountReport-20130905.xlsx
9/5/2013 11:25:48 AM, Closing Excel workbook...
9/5/2013 11:25:48 AM, Quitting Excel...
9/5/2013 11:25:58 AM, Report Complete. Sending report to:
stricklandgk@blahblah - Subj: Inactive AD Account Report
9/5/2013 11:25:58 AM, Trying SMTP Server relay.blahblah on port 25.
9/5/2013 11:25:59 AM, Succesfully sent email to:
stricklandgk@blahblah