Closing an Excel Application object with COM Interop is
actually a bit tricky. Try code like this:
Private Sub ReleaseCOMObjec t(ByVal pobj as Object)
Try
System.Runtime. InteropServices .Marshal.Releas eComObject
(pobj)
Catch
Finally
pobj = Nothing
End Try
End Sub
Private Sub ReadExcelFile()
Dim objApplication As Excel.Applicati on
Dim objWorkbooks As Excel.Workbooks
Dim objWorkbook As Excel.Workbook
Dim strFileName as String
Try
strFileName = "ExcelFile. xls"
objApplication = New Excel.Applicati on
objApplication. DisplayAlerts = False
objWorkbooks = objApplication. Workbooks
objWorkbooks.Op en(strFileName)
objWorkbook = objWorkbooks(1)
' Work with data, making sure to use explicitly
' defined objects for each object or collection
' accessed.
' objWorkbook.Sav eAs(strFileName & ".htm", 44)
objWorkbook.Clo se(False)
Catch ex as Exception
' Display error
Finally
ReleaseCOMObjec t(objWorkbook)
ReleaseCOMObjec t(objWorkbooks)
Try
objApplication. Quit()
Catch
End Try
ReleaseCOMObjec t(objApplicatio n)
Try
Kill(strFileNam e)
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
.