Hi,
I am using Windows 7 and Office 2007 :
I am instantiating excel from vba access, do some formatting on the excel spreadsheet, than close it.
I realise that the excel instance is still appearing in the task manager.
Here is the code:
*****************************************************************************
Private Sub btnTEST2_Click()
'------------------------------------------------------------
' btnTEST2_Click
'
'------------------------------------------------------------
On Error GoTo btnTEST2_Click_Err
Dim xlObj As Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlRange As Range
Dim Msg As String
Dim MyRange As String
Dim MyTestExcelClosure As String
Set xlObj = CreateObject("excel.application")
xlObj.Visible = False
MyTestExcelClosure = "C:\Test\MyTestExcelClosure.xlsx"
Set xlWorkbook = xlObj.Workbooks.Open(MyTestExcelClosure)
Set xlSheet = xlObj.ActiveSheet
xlObj.ActiveWorkbook.Names.Add Name:="Catégorie_No", RefersToR1C1:="=Report!R1C3"
xlObj.ActiveWorkbook.Names.Add Name:="Compte_No", RefersToR1C1:="=Report!R1C5"
xlObj.ActiveWorkbook.Names.Add Name:="CompteDescr", RefersToR1C1:="=Report!R1C6"
xlObj.ActiveWorkbook.Names.Add Name:="MontantDate", RefersToR1C1:="=Report!R1C7"
Set xlRange = xlSheet.Cells.Range("a1")
Selection.CurrentRegion.Sort _
key1:=Range("Catégorie_No"), order1:=xlAscending, _
key2:=Range("Compte_No"), order2:=xlAscending, _
key3:=Range("MontantDate"), order2:=xlAscending, _
Header:=xlYes
btnTEST2_Click_Exit:
On Error Resume Next
Set xlRange = Nothing
DoEvents
Set xlSheet = Nothing
DoEvents
Set xlWorkbook = Nothing
DoEvents
xlObj.Quit
Set xlObj = Nothing
DoEvents
Exit Sub
btnTEST2_Click_Err:
MsgBox Error$
Resume btnTEST2_Click_Exit
End Sub
*****************************************************************************
If I remove the sort statement, “Selection.CurrentRegion.Sort _” etc…, then the excel instance disappears from the task manager.
But if I keep the sort statement, there is no way to close that instance of Excel.
There is absolutely no other instance of excel in the task manager before running the code.
Any clues anyone?
Thank you in advance.
Alex
I am using Windows 7 and Office 2007 :
I am instantiating excel from vba access, do some formatting on the excel spreadsheet, than close it.
I realise that the excel instance is still appearing in the task manager.
Here is the code:
*****************************************************************************
Private Sub btnTEST2_Click()
'------------------------------------------------------------
' btnTEST2_Click
'
'------------------------------------------------------------
On Error GoTo btnTEST2_Click_Err
Dim xlObj As Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlRange As Range
Dim Msg As String
Dim MyRange As String
Dim MyTestExcelClosure As String
Set xlObj = CreateObject("excel.application")
xlObj.Visible = False
MyTestExcelClosure = "C:\Test\MyTestExcelClosure.xlsx"
Set xlWorkbook = xlObj.Workbooks.Open(MyTestExcelClosure)
Set xlSheet = xlObj.ActiveSheet
xlObj.ActiveWorkbook.Names.Add Name:="Catégorie_No", RefersToR1C1:="=Report!R1C3"
xlObj.ActiveWorkbook.Names.Add Name:="Compte_No", RefersToR1C1:="=Report!R1C5"
xlObj.ActiveWorkbook.Names.Add Name:="CompteDescr", RefersToR1C1:="=Report!R1C6"
xlObj.ActiveWorkbook.Names.Add Name:="MontantDate", RefersToR1C1:="=Report!R1C7"
Set xlRange = xlSheet.Cells.Range("a1")
Selection.CurrentRegion.Sort _
key1:=Range("Catégorie_No"), order1:=xlAscending, _
key2:=Range("Compte_No"), order2:=xlAscending, _
key3:=Range("MontantDate"), order2:=xlAscending, _
Header:=xlYes
btnTEST2_Click_Exit:
On Error Resume Next
Set xlRange = Nothing
DoEvents
Set xlSheet = Nothing
DoEvents
Set xlWorkbook = Nothing
DoEvents
xlObj.Quit
Set xlObj = Nothing
DoEvents
Exit Sub
btnTEST2_Click_Err:
MsgBox Error$
Resume btnTEST2_Click_Exit
End Sub
*****************************************************************************
If I remove the sort statement, “Selection.CurrentRegion.Sort _” etc…, then the excel instance disappears from the task manager.
But if I keep the sort statement, there is no way to close that instance of Excel.
There is absolutely no other instance of excel in the task manager before running the code.
Any clues anyone?
Thank you in advance.
Alex