R
Ray_nl
Hi,
I've got a problem with Access and Excel.
The situation: from Access2000 i create a Pivot-table in Excel2000. This
works like a charm. However I need to close Access before creating a 2nd
Pivot because an Excel-process remains in memory.
I think I've eliminated all implicit references but it doesnt seem to close
the excel.exe process when I quit Excel.
Ive included 'the code I use below. Does anyone have any suggestions?
Thnx in advance!
Public Function TestExcel()
Dim objXLApp As New Excel.Application
Dim objXLBook As Excel.Workbook
Dim strDatabase As String
Dim strSavename As String
objXLApp.Workbooks.Add
Set objXLBook = objXLApp.ActiveWorkbook
strDatabase = CurrentDb.Name
With objXLApp.ActiveWorkbook.PivotCaches.Add(SourceType:=xlExternal)
.Connection = Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=" & strDatabase &
";DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;"))
.CommandType = xlCmdSql
.CommandText = "SELECT ObjectType, obj_code, Jaar, Score FROM
qScore_Object_Code_Jaar_Gemiddeld ORDER BY ObjectType"
.CreatePivotTable TableDestination:="", TableName:="Draaitabel1"
End With
objXLBook.Sheets(1).Select
objXLApp.ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells
(3, 1)
objXLApp.ActiveSheet.Cells(3, 1).Select
objXLApp.ActiveSheet.PivotTables("Draaitabel1").SmallGrid = False
objXLApp.Charts.Add
objXLApp.ActiveChart.SetSourceData Source:=Sheets("Blad4").Range("A3")
objXLApp.ActiveChart.Location Where:=xlLocationAsNewSheet
With objXLApp.ActiveChart.PivotLayout.PivotFields("Score")
.Orientation = xlDataField
.Position = 1
End With
With objXLApp.ActiveChart.PivotLayout.PivotFields("obj_code")
.Orientation = xlRowField
.Position = 1
End With
With objXLApp.ActiveChart.PivotLayout.PivotFields("Jaar")
.Orientation = xlColumnField
.Position = 1
End With
objXLApp.ActiveChart.ChartType = xlLineMarkers
objXLApp.ActiveChart.Location Where:=xlLocationAsNewSheet
With objXLApp.ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
With objXLApp.ActiveChart.PivotLayout.PivotFields("ObjectType")
.Orientation = xlPageField
.Position = 1
End With
objXLApp.ActiveChart.PivotLayout.PivotFields("ObjectType").CurrentPage =
"PART145"
strSavename = CurrentProject.Path & "\Pivot\Pivot " & Replace(Now(), ":",
"") & ".xls"
objXLBook.SaveAs strSavename
MsgBox "The Pivotchart has been created and saved. " & vbCrLf & _
"It has been saved to: " & vbCrLf & strSavename, vbInformation, "Save
Information"
objXLBook.Close
objXLApp.Application.Quit
Set objXLBook = Nothing
Set objXLApp = Nothing
End Function
I've got a problem with Access and Excel.
The situation: from Access2000 i create a Pivot-table in Excel2000. This
works like a charm. However I need to close Access before creating a 2nd
Pivot because an Excel-process remains in memory.
I think I've eliminated all implicit references but it doesnt seem to close
the excel.exe process when I quit Excel.
Ive included 'the code I use below. Does anyone have any suggestions?
Thnx in advance!
Public Function TestExcel()
Dim objXLApp As New Excel.Application
Dim objXLBook As Excel.Workbook
Dim strDatabase As String
Dim strSavename As String
objXLApp.Workbooks.Add
Set objXLBook = objXLApp.ActiveWorkbook
strDatabase = CurrentDb.Name
With objXLApp.ActiveWorkbook.PivotCaches.Add(SourceType:=xlExternal)
.Connection = Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=" & strDatabase &
";DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;"))
.CommandType = xlCmdSql
.CommandText = "SELECT ObjectType, obj_code, Jaar, Score FROM
qScore_Object_Code_Jaar_Gemiddeld ORDER BY ObjectType"
.CreatePivotTable TableDestination:="", TableName:="Draaitabel1"
End With
objXLBook.Sheets(1).Select
objXLApp.ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells
(3, 1)
objXLApp.ActiveSheet.Cells(3, 1).Select
objXLApp.ActiveSheet.PivotTables("Draaitabel1").SmallGrid = False
objXLApp.Charts.Add
objXLApp.ActiveChart.SetSourceData Source:=Sheets("Blad4").Range("A3")
objXLApp.ActiveChart.Location Where:=xlLocationAsNewSheet
With objXLApp.ActiveChart.PivotLayout.PivotFields("Score")
.Orientation = xlDataField
.Position = 1
End With
With objXLApp.ActiveChart.PivotLayout.PivotFields("obj_code")
.Orientation = xlRowField
.Position = 1
End With
With objXLApp.ActiveChart.PivotLayout.PivotFields("Jaar")
.Orientation = xlColumnField
.Position = 1
End With
objXLApp.ActiveChart.ChartType = xlLineMarkers
objXLApp.ActiveChart.Location Where:=xlLocationAsNewSheet
With objXLApp.ActiveChart
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
With objXLApp.ActiveChart.PivotLayout.PivotFields("ObjectType")
.Orientation = xlPageField
.Position = 1
End With
objXLApp.ActiveChart.PivotLayout.PivotFields("ObjectType").CurrentPage =
"PART145"
strSavename = CurrentProject.Path & "\Pivot\Pivot " & Replace(Now(), ":",
"") & ".xls"
objXLBook.SaveAs strSavename
MsgBox "The Pivotchart has been created and saved. " & vbCrLf & _
"It has been saved to: " & vbCrLf & strSavename, vbInformation, "Save
Information"
objXLBook.Close
objXLApp.Application.Quit
Set objXLBook = Nothing
Set objXLApp = Nothing
End Function