Excel & Cannot create automation object & scheduled agent

I am having a problem with an automated agent. Everything works fine if I run in manually but fails when it runs as a scheduled agent when it gets to the line:

Set xlApp = CreateObject(“Excel.Application”)

it comes up in the log saying “Cannot create automation object”.

Excel is installed on the server, and the agent is set to run with full administration rights. I tried opening excel and changing the above line to

set xlApp = GetObject(“Excel.Application”) but it comes up with the same error message.

I can run the agent manually on the server with no problems.

If anyone has any pointers…

Subject: Excel & Cannot create automation object & scheduled agent

Can we see all of the code?

brandt

Subject: RE: Excel & Cannot create automation object & scheduled agent

Dim session As New NotesSessionDim txtFilename As String

Dim flag As Variant

Dim xlApp As Variant

Dim xlWkBook As Variant

Dim xlSheet As Variant

Dim xlSheet2 As Variant

Dim prodCol As NotesDocumentCollection

Dim scrapCol As NotesDocumentCollection

Dim x As Integer

Dim y As Integer

Dim agent As NotesAgent

Dim agentLog As New NotesLog(“Agent log”)

flag = False

On Error Goto GeneralError

On Error 213 Goto errorAccess

Set db = session.CurrentDatabase

Call agentLog.OpenAgentLog

'start the log off

Call agentLog.LogAction(“Excel export of production and scrap started”)

txtFilename = GetExportFilename(“ProductionAndScrap”)

If txtFilename = “Error” Then

Call agentLog.LogError(0, “The Export Filename document is missing from the Configuration menu, cannot complete the export”)

Exit Sub

End If

If txtFilename = “” Then

Call agentLog.LogError(0, “There is no filename in the This Years Production and Scrap field of the Export Filenames document, cannot continue with export”)

Exit Sub

End If

'we’ve got the filename, make sure the file is there

flag = CheckFileExists(txtFilename)

If Not flag Then

Call agentLog.LogError(0, "The excel file called " + txtFilename + " does not exist.  The export cannot continue.")

Exit Sub

End If

'count the production first

Set prodCol = GetDocCollection(“production”)

If prodCol.Count > 0 Then

Call CountColl(prodCol, "prod") 

End If

'count the scrap

Set scrapCol = GetDocCollection(“scrap”)

If scrapCol.Count > 0 Then

Call CountColl(scrapCol, "scrap")

End If

If (prodCol.Count > 0) Or (scrapCol.Count > 0) Then

'we only want to write to the spreadsheet if we have some information to write

'create the spreadsheet

Print (“Creating Excel object”)

Set xlApp = CreateObject(“Excel.Application”)

xlApp.Visible = False

xlApp.Application.DisplayAlerts = False

Print (“Opening Spreadsheet”)

xlApp.Workbooks.Open txtFilename

Print (“Opening Worksheets”)

Set xlSheet = xlApp.Workbooks(1).Worksheets(1)

Set xlSheet2 = xlApp.Workbooks(1).Worksheets(2)

Set xlWkBook = xlApp.ActiveWorkbook

xlSheet.Activate

Print (“Writing Production Figures to spreadsheet”)

'if we have some production data, write it to the first sheet

If prodCol.Count > 0 Then

Call WriteArrayToSheet(xlSheet, "prod")

End If

Print (“Writing Scrap Figures to spreadsheet”)

If scrapCol.Count > 0 Then

Call WriteArrayToSheet(xlSheet2, "scrap")

End If

'save the spreadsheet

Print(“Save & Close Spreadsheet”)

Call xlWkBook.saveas(txtFilename)

xlWkBook.Close

xlApp.DisplayAlerts = False

xlApp.Quit

Set xlApp = Nothing

Print(“”)

Call agentLog.LogAction(“Export production and scrap agent finished”)

Call agentLog.Close

Exit Sub

GeneralError:

Call agentLog.LogError(0, "The following error occured: " & Err & " : " & Error$)

Print(“”)

Exit Sub

errorAccess:

Call agentLog.LogError(0, "The Export production and scrap agent does not have access to the folder " & filename & " either change the name of the file you are trying to save, or speak to the IT Department to get access to the folder")

xlWkBook.Close

xlApp.DisplayAlerts = False

xlApp.Quit

Set xlApp = Nothing

Print(“”)

Exit Sub

If I click on Agent Run from the workstation software on the server, it runs fine with no errors. If I run it scheduled, after the line

Set xlApp = CreateObject(“Excel.Application”)

it comes up with cannot create automation object.

I

Subject: RE: Excel & Cannot create automation object & scheduled agent

log onto the server and open task manager and see if EXCEL.EXE is already running. I’ve seen the error occur if Excel was already running and you try to open it again.

Subject: RE: Excel & Cannot create automation object & scheduled agent

no excel is not already running. I had an error report box on the screen about excel so I got rid of that, rebooted the server, checked that Excel is definately not running and then rescheduled the agent to run again. It comes up with the same error every time.

Once the agent has run there is an error report box on the screen about excel but excel running if I look in task manager.

I even tried having excel already open and changing the line to

Set xlApp = getObject(, “Excel.Application”)

but that makes the agent come up with the same error

Subject: RE: Excel & Cannot create automation object & scheduled agent

Have you ever actually opened Excel on the server? I know from experience that if you do not agree to the EULA that Excel brings up on first run, it will crash your agent.

that’s the only other thing I can think of.

Brandt

Subject: RE: Excel & Cannot create automation object & scheduled agent

Yes, I’ve opened Excel and opened the spreadsheet that the agent is trying to write to, all successfully. I’ve even tried running the agent manually from the server and that works OK as well. I tried running the agent without hiding excel to see what happened. I was watching the server as the scheduled agent ran, when it gets to where it trying to create the excel object, one of those windows error report windows comes up and then the agent writes to the log that it cannot create the automation object. I checked the windows error log and it comes up with an error saying “rejected safe mode action” so I’m going to check out the microsoft site to see what causes this

Subject: RE: Excel & Cannot create automation object & scheduled agent

I’ve found this from the microsoft sitehttp://support.microsoft.com/kb/288368/

so I’ll get them to do this on the server and then we’ll try again!!

Subject: RE: Excel & Cannot create automation object & scheduled agent

Helen,

Did you ever get this to work?

Thanks,

ASH

Subject: RE: Excel & Cannot create automation object & scheduled agent

I’ve also checked that there is a folder in the registry called Excel.Application