Reputation: 89
I am unable to save an Excel workbook using the code below on a server with a scheduled agent but it works on when I run it locally.
Error I get is:
Agent Manager: Agent message: INITIALIZE: - Error #213 - Microsoft Excel: SaveAs method of Workbook class failed @ line #37
We have Excel 2016 installed on Windows Server 2012. Domino Server version is 8.5.3 FP6
Code using:
Declarations
Dim xlApp As Variant, xlsheet As Variant, rows As Integer, cols As Integer, xlWorkBk As Variant
Dim SheetRows() As Integer 'the bound for sheetRows is the same as the sheetNukmber
Sub Initialize
On Error GoTo ErrorTrap
Dim st As String, aname As String, sname As String
st = CStr(GetThreadInfo(1)) + ": "
Dim sess As New NotesSession ,db As NotesDatabase
Dim agent As NotesAgent
Dim v As NotesView, vString As String, strMsg As String
Dim dc As NotesDocumentCollection
Dim doc As NotesDocument, maxcols As Integer
Dim a As Integer, range As String
Dim mgrList() As String, mgrTotal() As Currency
Dim x As Integer, mgrPcntg() As Double'GET SERVER NAME (COMMON)
Set db = sess.CurrentDatabase 'link to current database
If InStr(db.server,"/") Then
sName = Left(db.Server,InStr(db.server,"/")-1)
Else
sName = db.server
End If
'GET AGENT NAME (COMMON)
Set agent = sess.currentAgent
If InStr(agent.name,"|") Then
aName = Left(agent.name,InStr(agent.name,"|")-1)
Else
aName = agent.Name
End If
Set xlApp = CreateObject("Excel.Application") 'start Excel with OLE Automation
xlApp.Visible = False
xlApp.Workbooks.Add
'- - - - - - Adding data from Notes here - - - - -
'- - - - - - formatting worksheet - - - - - -
'- - - - - - I Get Error 213 at Next Line - - - - - -
'INITIALIZE: - Error #213 - Microsoft Excel: SaveAs method of Workbook Class failed @ Line #37
Call xlApp.ActiveWorkbook.SaveAs("C:\Temp\MikesTest.xlsx", 51) ',51)
xlApp.Quit
GoTo EndOfCode
ERRORTRAP:
strMsg = st + " - Error #" & Err & " - " & Error$ & " @ line #" & Erl
MsgBox strMsg
xlApp.quit
Exit Sub
ENDOFCODE:
End Sub
Checked permissions of agent signer and it is allowed. Checked file folder restrictions and there is none. Searched Internet for hours with no success in finding solution.
Tried xlApp.ActiveWorkbook.SaveAs("C:\Temp\MikesTest.xlsx")
and same issue.
Upvotes: 1
Views: 1731
Reputation: 89
Got it to work by making a few changes to our server. Starting with Windows 2008, Microsoft changed security model. IBM was extremely helpful although this is not their problem. This is what we did. 1. For the IBM Domino Service, changed the properties under the Log On tab to use an account to log on. 2.Stopped and restarted the Domino service. 3.We added the following directory "C:\Windows\SysWOW64\config\systemprofile\Desktop". 4. Saved the file to this directory.
Upvotes: 1
Reputation: 50034
I'm not sure what the issue is, but it could be the activeWorkbook
attribute of the xlApp
object that might not make sense in the remote context you are working in on your server. Instead when you open the new workbook, assign it to a variable, and then use that workbook object variable directly to save it:
Set xlApp = CreateObject("Excel.Application") 'start Excel with OLE Automation
xlApp.Visible = False
Dim xlWB As Object
Set xlWB = xlApp.Workbooks.Add
xlWB.SaveAs("C:\Temp\MikesTest.xlsx", 51) ',51)
Set xlWB = Nothing
xlApp.Quit
Upvotes: 0