Hi Andrew,
Thanks for the help,. one problem resolved and straight into another. Unfortunately I cannot resolve this using a report, it has to be an excel file.
My code is now firing but I am getting a different error
Code:
Protected Overrides Sub Execute(executioncontext As CodeActivityContext)
Try
Dim xlApp As Excel.Application = New Microsoft.Office.Interop.Excel.Application()
' just for testing
Using sw As StreamWriter = File.AppendText("\\CBI018\EDDS\Logs\excel.txt")
sw.WriteLine("Started")
End Using
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
xlWorkBook = xlApp.Workbooks.Add(misValue)
xlWorkSheet = xlWorkBook.Sheets("Monthly Report.xls")
xlWorkSheet.Cells(1, 1) = "Test"
xlWorkBook.SaveAs("C:\Temp\120004 Monthly Report.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue,
Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue)
xlWorkBook.Close(True, misValue, misValue)
xlApp.Quit()
releaseObject(xlWorkSheet)
releaseObject(xlWorkBook)
releaseObject(xlApp)
Using sw As StreamWriter = File.AppendText("\\CBI018\EDDS\Logs\excel.txt")
sw.WriteLine("Finished")
End Using
Catch ex As Exception
Using sw As StreamWriter = File.AppendText("\\CBI018\EDDS\Logs\excel.txt")
sw.WriteLine("Update To " & ex.Message.ToString)
End Using
End Try
End Sub
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
Using sw As StreamWriter = File.AppendText("\\CBI018\EDDS\Logs\excel.txt")
sw.WriteLine("Error Closing " & ex.Message.ToString
)
End Using
Finally
GC.Collect()
End Try
End Sub
The error I'm getting now is
Update To Microsoft Excel cannot open or save any more documents because there is not enough available memory or disk space.
• To make more memory available, close workbooks or programs you no longer need.
• To free disk space, delete files you no longer need from the disk you are saving to.
I am saving to a local directory on the CRM server ( till I get this working ) . When looking at the services, I can see the Excel application service running. I have plenty on memory on this server ( Win 2016 server running CRM 2016. 20Gb mem and 4 processors ) . I have over 200GB of free disc space, so I don't understand why this error is occouring