Excel application still running in background after Application.Quit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm formatting an Excel workbook from an Inventor macro, but after a selection range of cell the cycle "With, End With" doesn't allow Excel to close properly and remain open in background preventing the code to continue.
Any help is appreciate
Dim XL As Excel.Application
Dim xlWB As Excel.Workbook
Dim xlWS As Excel.WorkSheet
Set XL = CreateObject("Excel.Application")
Set xlWB = XL.Workbooks.Open("c:\temp\" & name & ".xlsx")
Set xlWS = xlWB.Worksheets(1)
XL.Visible = False 'True
xlWS.Activate
xlWS.Rows("1:1").HorizontalAlignment = XlHAlign.xlHAlignCenter
xlWS.Rows("1:1").Font.Bold = True
xlWS.Columns("A:A").ColumnWidth = 6
xlWS.Columns("B:B").ColumnWidth = 22
xlWS.Columns("C:C").ColumnWidth = 18
xlWS.Columns("D:D").ColumnWidth = 45
xlWS.Columns("E:E").ColumnWidth = 6
xlWS.Range("A1:E1").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
xlWB.Save
xlWB.Close True
XL.Application.Quit
Set xlWS = Nothing
Set xlWB = Nothing
Set XL = Nothing
Exit Sub
End Sub


