Question : Opening Excel from Access causes Access to crash

I have an Access 2007 database I use to create and format Excel reports for a large team. It has been working just fine up to a couple days ago. Then it started giving me a "Access has encountered an error and needs to close" popup.  Using some MsgBoxes I was able to determine that the error occurs in a subroutine that opens an existing Excel file, deletes some extraneous columns of code (no headers and sometimes garbage characters live there), saves and closes the file.
If I comment out the lines

Set xlApp = New Excel.Application and     Set xlApp = Nothing

then it works OK.  Note that I have to comment out the xlApp lines in a couple other, but not all, places it exists in the code. But of course, if I do that, I do not get the tweeks I need.

Any ideas what could be causing this to decide to fail now?   I have added the actual code below for one of the subs that is causing the problem.  Another opens an existing Excel file and formats specific cells, fills, bold, that kind of thing.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
Sub TweakMetricsReport()

Dim xlApp As Excel.Application
Dim filePath As String

filePath = CurrentProject.path & "\Linked\metrics_report.xls"
    
    On Error Resume Next
    Set xlApp = New Excel.Application
    xlApp.Visible = False
    xlApp.Workbooks.Open FileName:=filePath, ReadOnly:=False
    
    xlApp.sheets("data").Select
    xlApp.Columns("BY:CZ").Select
    xlApp.Selection.Delete Shift:=xlToLeft
    xlApp.ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
    
    xlApp.ActiveWorkbook.Save
    xlApp.ActiveWorkbook.Close
    xlApp.Quit
    
    Set xlApp = Nothing

End Sub

Answer : Opening Excel from Access causes Access to crash

I have no idea why this worked but I did two things and now the database is working normally. I changed the order of the references, moved the Excel Object library up further to the top of the list and added the MS Word Object library. No other changes and now it's working. It's too late for me to remove one to see which one allowed it to work.

Thanks Torrwin for your help. I am still clueless as to why these two changes allowed the database to start working again, especially since I had not changed anything before it stopped working.

Happy Holidays to All
Random Solutions  
 
programming4us programming4us