G
GeorgeAtkins
I am using Office 2003.
I have an Access database that opens Excel to insert data into a series of
workbooks. The subroutine containing this code is called from within a loop
of another routine. The problem is that when the loop is finished, Excel
Automation objects are still in memory: I open the Task Manager and there
they are! But I thought my code should have closed them. Here is that code:
Sub UpdateExcelFiles(col As Integer, sname As String, att As Single, mbr As
Single, WUnits As Variant)
Dim y As Integer
Dim xlAPP As Excel.Application
Dim xlRange As Excel.Range
Set xlAPP = CreateObject("Excel.Application")
xlAPP.Workbooks.Open "H:\SDL Tracking Sheets\" & sname & ".xls"
For y = 0 To UBound(WUnits, 2) - 1
With xlSheet.Range("CourseIDs")
Set xlRange = .Find(WUnits(0, y))
If Not xlRange Is Nothing Then
xlAPP.Range(xlRange.Address).Select
xlAPP.ActiveCell.Offset(0, 5 + col) = WUnits(1, y)
End If
End With
Next y
xlAPP.Range("AvgAttd").Offset(0, col) = (att / mbr)
xlAPP.ActiveWorkbook.Close True
xlAPP.Application.Quit
Set xlAPP = Nothing
Set xlRange = Nothing
End Sub
******
Ok. What am I doing wrong? Why isn't Excel closing?
And, is there a more efficient way to do this? I mean, should I be opening
and closing the Excel automation object over and over?
Thanks for any tips!
I have an Access database that opens Excel to insert data into a series of
workbooks. The subroutine containing this code is called from within a loop
of another routine. The problem is that when the loop is finished, Excel
Automation objects are still in memory: I open the Task Manager and there
they are! But I thought my code should have closed them. Here is that code:
Sub UpdateExcelFiles(col As Integer, sname As String, att As Single, mbr As
Single, WUnits As Variant)
Dim y As Integer
Dim xlAPP As Excel.Application
Dim xlRange As Excel.Range
Set xlAPP = CreateObject("Excel.Application")
xlAPP.Workbooks.Open "H:\SDL Tracking Sheets\" & sname & ".xls"
For y = 0 To UBound(WUnits, 2) - 1
With xlSheet.Range("CourseIDs")
Set xlRange = .Find(WUnits(0, y))
If Not xlRange Is Nothing Then
xlAPP.Range(xlRange.Address).Select
xlAPP.ActiveCell.Offset(0, 5 + col) = WUnits(1, y)
End If
End With
Next y
xlAPP.Range("AvgAttd").Offset(0, col) = (att / mbr)
xlAPP.ActiveWorkbook.Close True
xlAPP.Application.Quit
Set xlAPP = Nothing
Set xlRange = Nothing
End Sub
******
Ok. What am I doing wrong? Why isn't Excel closing?
And, is there a more efficient way to do this? I mean, should I be opening
and closing the Excel automation object over and over?
Thanks for any tips!