I am running the following relevant code in a Windows Service app designed to create reports by transforming XML data from a dataset into excel readable XML. Because Office XP has not been rolled out to all of our users, I have to automate Excel on the server in order to save the XML version of the file in an Excel Spreadsheet format.
It generates the following error the SECOND TIME it is run, never the first:
"The message filter indicated that the application is busy"
It errors on the line that includes "xlaApp.Ready" in this version, but generally errors on the first reference to the xlaApp Excel.Application variable following opening the workbook.
Here is the code:
GC.Collect()
xlaApp = New Excel.Application()
xlaApp.AlertBeforeOverwriting = False
xlaApp.DisplayAlerts = False
xlaApp.Visible = False
xlWB = xlaApp.Workbooks.Open(sFolder & sExcelXML)
Dim nlCount As Short = 0
While Not xlaApp.Ready
System.Threading.Thread.Sleep(500)
nlCount += 1
If nlCount >= 60 Then Throw New System.Runtime.InteropServices.COMException("EXCEL application not ready - timeout expired")
End While
xlWB.SaveAs(sFolder & sNewFile, 1)
xlWB.Close()
xlaApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWB)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlaApp)
xlWB = Nothing
xlaApp = Nothing
GC.Collect()
It generates the following error the SECOND TIME it is run, never the first:
"The message filter indicated that the application is busy"
It errors on the line that includes "xlaApp.Ready" in this version, but generally errors on the first reference to the xlaApp Excel.Application variable following opening the workbook.
Here is the code:
GC.Collect()
xlaApp = New Excel.Application()
xlaApp.AlertBeforeOverwriting = False
xlaApp.DisplayAlerts = False
xlaApp.Visible = False
xlWB = xlaApp.Workbooks.Open(sFolder & sExcelXML)
Dim nlCount As Short = 0
While Not xlaApp.Ready
System.Threading.Thread.Sleep(500)
nlCount += 1
If nlCount >= 60 Then Throw New System.Runtime.InteropServices.COMException("EXCEL application not ready - timeout expired")
End While
xlWB.SaveAs(sFolder & sNewFile, 1)
xlWB.Close()
xlaApp.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWB)
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlaApp)
xlWB = Nothing
xlaApp = Nothing
GC.Collect()