Although this code works, its leaving an instance of Excel open. What am I doing wrong?
Dim xlApp As New Excel.Application
Dim wb1 As Workbook
Set xlApp = New Excel.Application
Set wb1 = xlApp.Workbooks.Open("c:\chi\sla.xlsx")
wb1.Sheets.Add
wb1.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Qry1!R1C1:R2539C5", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="Sheet1!R3C1", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion14
wb1.Sheets("Sheet1").Select
wb1.ActiveSheet.Cells(3, 1).Select
wb1.ActiveSheet.PivotTables("PivotTable1").AddData Field ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Tran_Amount"), "Sum of Tran_Amount", xlSum
xlApp.ActiveWorkbook.Close (True)
Set wb1 = Nothing
Set xlApp = Nothing