Closing an Excel Application object with COM Interop is
actually a bit tricky. Try code like this:
Private Sub ReleaseCOMObject(ByVal pobj as Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComO bject
(pobj)
Catch
Finally
pobj = Nothing
End Try
End Sub
Private Sub ReadExcelFile()
Dim objApplication As Excel.Application
Dim objWorkbooks As Excel.Workbooks
Dim objWorkbook As Excel.Workbook
Dim strFileName as String
Try
strFileName = "ExcelFile.xls"
objApplication = New Excel.Application
objApplication.DisplayAlerts = False
objWorkbooks = objApplication.Workbooks
objWorkbooks.Open(strFileName)
objWorkbook = objWorkbooks(1)
' Work with data, making sure to use explicitly
' defined objects for each object or collection
' accessed.
' objWorkbook.SaveAs(strFileName & ".htm", 44)
objWorkbook.Close(False)
Catch ex as Exception
' Display error
Finally
ReleaseCOMObject(objWorkbook)
ReleaseCOMObject(objWorkbooks)
Try
objApplication.Quit()
Catch
End Try
ReleaseCOMObject(objApplication)
Try
Kill(strFileName)
Catch ex as Exception
' Display reason why file could not be deleted
End Try
End Try
End Sub
- Dave Davidson (MCP)
-----Original Message-----
Hi,
I have a web app whereby I extract some data from an
Excel Sheet.
Once I have extracted my data I close my Excel Object.
I then try to delete the file.
When I try to delete the file it tells me that it is
locked by the IUSR account.
Anyone know why this is?
Thanks,
C
.