W
Winfried
Hi,
I have a problem. I use Windows XP, SP2,ACCESS 2003 SP2.
In an ACCESS sub I open an Excel file to process it. Afterwards I close
it. Unfortunately the Excel remains open respectively is visible when I
have a look into the task manager. This causes further problems in my
program.
The small extract of my VBA code looks as follows:
-----------------------------------------------------
Sub TEST()
Dim objExcelApp As Excel.Application
Dim objExcelWb As Excel.Workbook
Dim lastRecordExcel As Integer
Dim i As Integer
Dim ImportFile As String
ImportFile = "c:\temp\testExcelfile.xls"
' Make connection to Excel
Set objExcelApp = New Excel.Application
objExcelApp.Application.Workbooks.Open ImportFile
Set objExcelWb = objExcelApp.Application.Workbooks(1)
' Find last blank record from top in column 1
lastRecordExcel = objExcelWb.Worksheets(1).Cells(Rows.count,
1).End(xlUp).Row
'...
' Here come further VBA commands
'....
' Close and destroy the Excel object
objExcelWb.Close
Set objExcelWb = Nothing
objExcelApp.Quit
Set objExcelApp = Nothing
End Sub
-----------------------------------------------------
But now the best: when I comment out the assignment to variable
lastRecordExcel respectively replace it by the following
'while'-command
-------------
i = 6
While objExcelWb.Worksheets(1).Cells(i, 1) <> ""
i = i + 1
Wend
lastRecordExcel = i - 1
-------------
Excel will be closed correctly.
Can someone give me a hint to solve the problem.
Best regards,
Winfried
(Remark: The behaviour is the same when I use this code inside Word
2003, if I use it inside Excel 2003 all works fine)
I have a problem. I use Windows XP, SP2,ACCESS 2003 SP2.
In an ACCESS sub I open an Excel file to process it. Afterwards I close
it. Unfortunately the Excel remains open respectively is visible when I
have a look into the task manager. This causes further problems in my
program.
The small extract of my VBA code looks as follows:
-----------------------------------------------------
Sub TEST()
Dim objExcelApp As Excel.Application
Dim objExcelWb As Excel.Workbook
Dim lastRecordExcel As Integer
Dim i As Integer
Dim ImportFile As String
ImportFile = "c:\temp\testExcelfile.xls"
' Make connection to Excel
Set objExcelApp = New Excel.Application
objExcelApp.Application.Workbooks.Open ImportFile
Set objExcelWb = objExcelApp.Application.Workbooks(1)
' Find last blank record from top in column 1
lastRecordExcel = objExcelWb.Worksheets(1).Cells(Rows.count,
1).End(xlUp).Row
'...
' Here come further VBA commands
'....
' Close and destroy the Excel object
objExcelWb.Close
Set objExcelWb = Nothing
objExcelApp.Quit
Set objExcelApp = Nothing
End Sub
-----------------------------------------------------
But now the best: when I comment out the assignment to variable
lastRecordExcel respectively replace it by the following
'while'-command
-------------
i = 6
While objExcelWb.Worksheets(1).Cells(i, 1) <> ""
i = i + 1
Wend
lastRecordExcel = i - 1
-------------
Excel will be closed correctly.
Can someone give me a hint to solve the problem.
Best regards,
Winfried
(Remark: The behaviour is the same when I use this code inside Word
2003, if I use it inside Excel 2003 all works fine)