Search code examples
vb.netserviceexcel-interop

VB.Net Service doesn't seem to be able to use Excel Interop to export files


I have a service that data logs devices and records the info to a SQL Server. Each night at a random time after midnight I export out multiple excel documents to temp files then upload them to SharePoint. If I run the service code normally (by copying and pasting it to a form app for testing) the export work as expected. But when the service runs it I get a "The remote procedure call failed. (Exception from HRESULT: 0x800706BE)".

Is this a limitation of running the interops as a service? I can't see anything else that it could be since the code does work normally in a form app.

Couple things I have found online that did not help:

  • Make sure the directory C:\Windows\SysWOW64\config\systemprofile\Desktop exists. It does.
  • Make sure you are using local files and not ones form network resources. I am, it creates temp files using IO.Path.GetTempFileName
  • Switched to a user account instead of the Local System account for the service. No change.

Solution

  • I switched over to ClosedXML to generate the Excel file without using Office Interop and now everything works when running as a Service.