|
-
Jun 14th, 2013, 03:36 PM
#1
Thread Starter
Junior Member
Excel Taking Ages to Unload
I am opening an Excel file from VB, saving some data to a sheet and then closing the file. For some reason when I close Excel, it seems to take up to a minute to unload (looking at task manager). If I open a saved XLS file before it closes properly, it doesn't display the contents of the sheet, just a transparent window through which I can see the desktop. Is it the case that I am not closing the workbook, worksheet and application down properly, and some "housekeeping" routine in the background is doing this for me after a timeout period?
This is the code:
Code:
Dim oXL As Object
Dim oWB As Object
Dim oSheet As Object
Private Sub excelopen()
'Start Excel and get Application object.
oXL = CreateObject("Excel.Application")
' Add a new workbook....
oWB = oXL.Workbooks.add
oXL.Visible = True
oSheet = oWB.sheets(1)
oXL.UserControl = False
' Prevent user editing worksheet
oXL.interactive = False
' Don't display warnings warnings in Excel
oXL.DisplayAlerts = False
End Sub
Private Sub excelwrite(ByVal value_to_write As String, ByVal row As Integer, ByVal column As Integer)
Try
oSheet.unprotect()
' store some data in cells here
oSheet.columns.autofit()
oSheet.protect()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub excelclose()
oSheet = Nothing
Try
oWB.SaveAs(My.Computer.FileSystem.SpecialDirectories.Desktop & "\test.xls")
Catch ex As Exception
MsgBox(ex.Message)
End Try
oWB.Close(SaveChanges:=False)
' Close references and release memory
oWB = Nothing
oXL.interactive = True
oXL.DisplayAlerts = True
oXL.Quit()
oXL = Nothing
End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|