I am having trouble determining why the following code opens an instance of Excel, but doesn’t close it. Is there something I am leaving out?
Thanks,
Function ReorderSheets(strFullPath As String)
Dim xlWrkbk As Excel.Workbook
Dim xlApp As Excel.Application
Dim i As Integer
On Error GoTo Err_ReorderSheets
‘ Create a Microsoft Excel object.
Set xlApp = CreateObject(“Excel.Application”)
‘ Open the spreadsheet
Set xlWrkbk = xlApp.Workbooks.Open(strFullPath)
‘ Rename the sheets
xlApp.DisplayAlerts = False
xlApp.Sheets(“XB”).Select
xlApp.Sheets(“XB”).Name = “City”
xlApp.Sheets(“XC”).Select
xlApp.Sheets(“XC”).Name = “City Pivot”
With xlApp
‘ Blank sheets
.Sheets.Add
.Sheets(“Sheet1”).Select
.Sheets(“Sheet1”).Name = “Reconciliation”
.Sheets.Add
.Sheets(“Sheet2”).Select
.Sheets(“Sheet2”).Name = “Reconciliation2”
.Sheets.Add
.Sheets(“Sheet3”).Select
.Sheets(“Sheet3”).Name = “Triangle Analysis”
‘ Reorder Sheets
.Sheets(“Core”).Move after:=Sheets(22)
.Sheets(“THEST”).Move after:=Sheets(21)
.Sheets(“Class”).Move Before:=Sheets(21)
.Sheets(“Prior Class”).Move Before:=Sheets(20)
.Sheets(“Prior Group”).Move Before:=Sheets(19)
.Sheets(“Legacy Analysis”).Move Before:=Sheets(18)
.Sheets(“Reconcile Lemons”).Move Before:=Sheets(17)
.Sheets(“Change Amounts”).Move Before:=Sheets(16)
.Sheets(“Trianglel Analysis”).Move Before:=Sheets(15)
.Sheets(“Policy Yr”).Move Before:=Sheets(14)
xlApp.Range(“A1″).Select
End With
Exit_ReorderSheets:
xlWrkbk.Close SaveChanges:=True
Set xlWrkbk = Nothing
‘ Quit Excel
xlApp.Quit
Set xlApp = Nothing
Exit Function
Err_ReorderSheets:
MsgBox CStr(Err) & ” ” & Err.Description
Resume Exit_ReorderSheets
End Function