Excel proccess running after export from Access

Just curious as to what I am doing wrong here. I have some code that exports a table to Excel and then manipulates it with some code. After everything is done I go in and look at the task manager and there is always an Excel process running. Here is my code:

 
DoCmd.OutputTo acOutputForm, "TESTTABLEFORMEXPORT", acFormatXLS, "c:\TestForm2.xls", False
    Dim xlObj As Object, xlFile As String
    xlFile = "c:\TestForm2.xls"
    Set xlObj = CreateObject("excel.application")
    xlObj.Workbooks.Open xlFile
    With xlObj
   
    
        .Columns("C:C").Select
    .Selection.FormatConditions.AddColorScale ColorScaleType:=3
    .Selection.FormatConditions(Selection.FormatConditions.count).SetFirstPriority
    .Selection.FormatConditions(1).ColorScaleCriteria(1).type = _
        xlConditionValueLowestValue
    With Selection.FormatConditions(1).ColorScaleCriteria(1).FormatColor
        .Color = 7039480
        .TintAndShade = 0
    End With
    .Selection.FormatConditions(1).ColorScaleCriteria(2).type = _
        xlConditionValuePercentile
    .Selection.FormatConditions(1).ColorScaleCriteria(2).Value = 50
    With Selection.FormatConditions(1).ColorScaleCriteria(2).FormatColor
        .Color = 8711167
        .TintAndShade = 0
    End With
    .Selection.FormatConditions(1).ColorScaleCriteria(3).type = _
        xlConditionValueHighestValue
    With Selection.FormatConditions(1).ColorScaleCriteria(3).FormatColor
        .Color = 8109667
        .TintAndShade = 0
    End With
    .Cells.Select
    .Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(4, 5, 6, 7, _
        8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20), Replace:=True, PageBreaks:=False, _
        SummaryBelowData:=True

    End With
    
     ActiveSheet.Outline.ShowLevels RowLevels:=2
    ActiveWorkbook.Save
    ActiveWorkbook.Close
    
    xlObj.Quit

    Set xlObj = Nothing

Open in new window


I tried adding this:

xlObj.Workbooks.Close xlFile

But it said 'Too few arguments'

What am I missing here? Thanks for any help you can give me.
LVL 1
G ScottAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

YohanFCommented:
try following:

xlObj.ActiveWorkbook.Save
xlObj.Quit
0
G ScottAuthor Commented:
Hey YohanF, tried your suggestion and the Excel process is still running:

 Still running
0
YohanFCommented:
Hi, I found the problem. Try this and see. This will assign the work book you open to a variable and save and close that instead of saving and closing the active sheet. This seems to have done the trick.

Before executing make sure you kill off any existing EXCEL processes.

Dim xlObj As Object
    Dim xlFile As String
    Dim xlwrkbk As Excel.Workbook
    
    xlFile = "c:\TestForm2.xls"
    Set xlObj = CreateObject("excel.application")
    
    xlObj.Workbooks.Open xlFile
    Set xlwrkbk = xlObj.Workbooks.Open(xlFile)
    
    With xlObj
        .Columns("C:C").Select
    .Selection.FormatConditions.AddColorScale ColorScaleType:=3
    .Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    .Selection.FormatConditions(1).ColorScaleCriteria(1).Type = _
        xlConditionValueLowestValue
    With Selection.FormatConditions(1).ColorScaleCriteria(1).FormatColor
        .Color = 7039480
        .TintAndShade = 0
    End With
    .Selection.FormatConditions(1).ColorScaleCriteria(2).Type = _
        xlConditionValuePercentile
    .Selection.FormatConditions(1).ColorScaleCriteria(2).Value = 50
    With Selection.FormatConditions(1).ColorScaleCriteria(2).FormatColor
        .Color = 8711167
        .TintAndShade = 0
    End With
    .Selection.FormatConditions(1).ColorScaleCriteria(3).Type = _
        xlConditionValueHighestValue
    With Selection.FormatConditions(1).ColorScaleCriteria(3).FormatColor
        .Color = 8109667
        .TintAndShade = 0
    End With
    .Cells.Select
    .Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(4, 5, 6, 7, _
        8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20), Replace:=True, PageBreaks:=False, _
        SummaryBelowData:=True

    End With
    
    ActiveSheet.Outline.ShowLevels RowLevels:=2
    
    xlwrkbk.Save
    xlwrkbk.Close
    
    xlObj.Quit

    Set xlObj = Nothing

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

G ScottAuthor Commented:
Hmmm..line 14:

.Selection.FormatConditions(Selection.FormatConditions.count).SetFirstPriority

is giving me a 462 error. 'Remote server machine does not exist or is unavailable"

Any idea??
0
G ScottAuthor Commented:
Ok..now the same line is giving me a '91' error:

Object variable or With block variable not set.

What the heck? That is strange...to me anyway.
0
YohanFCommented:
I saw you have opened a different thread for this. I am not very familiar with conditional formatting with VBA..
0
G ScottAuthor Commented:
Oh, yeah, that was sort of a separate issue. Yours is working by the way. For some reason, there were two Excel processes running. I killed the one and missed the other.

Thanks for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.