Search code examples
excelvb.netoffice-interop

Convert Excel to HTM file as a Scheduled Task on a Server


I have a program that does all types of conversions from different file types. The piece of functionality that converts files from Excel to HTM runs without error when the program is executed manually either on a personal machine or even on a windows server.

The issue happens when the program is scheduled as a task on a windows server. Error 0x800AC472 is thrown at Excel.Workbooks.Close().

My assumption is that this is a licensing issue on the server which throws an office activation dialog box causing the program to fail to close.

I want to replace using Office Interop with a package/library that is compatible with server side automation for such conversions. What are some libraries that support this requirement?

I currently handle the conversions using Office Interops within a Visual Basic console application.

Private Shared objXL As Excel.Application

GC.Collect()

    Dim objWB As Excel.Workbook

    Try

        objWB = objXL.Workbooks.Open(fileSource)

        objWB.SaveAs(fileDestination, Excel.XlFileFormat.xlHtml, , , False, False)
      
        objWB.Close(Nothing, Nothing, Nothing)

    Catch ex As Exception
        Throw ex
    End Try

    objXL.Workbooks.Close()
    System.Runtime.InteropServices.Marshal.ReleaseComObject(objWB)
    objWB = Nothing

GC.Collect() 

Solution

  • Creating the following directories fixed the issue where running office automation on a server created dialog boxes so the unattended execution failed since Office applications expect to be interacting with a real user and thus to close those dialog boxes.

    C:\Windows\SysWOW64\config\systemprofile\Desktop

    C:\Windows\System32\config\systemprofile\Desktop

    My operating system Windows Server 2012 R2 Standard