I used Ken Snell's site as a reference...
I've had problems with closing Excel from Access (2000). Sometimes the Excel process would stay running and I would have to open the task manager to close Excel. It seemed to be a timing problem, so I threw in several DoEvents commands.... seems to work.
Code:
Option Compare Database
Option Explicit
Private Sub Excelbtn_Click()
'requires a reference to DAO 3.6 Object Library
Dim xlx As Object
Dim xlw As Object
Dim xlst As Object
Dim xlc As Object
Dim blnEXCEL As Boolean
blnEXCEL = False
' Establish an EXCEL application object
On Error Resume Next
Set xlx = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set xlx = CreateObject("Excel.Application")
blnEXCEL = True
End If
Err.Clear
On Error GoTo 0
' Change True to False if you do not want the workbook to be
' visible when the code is running
xlx.Visible = True
' Replace C:\Filename.xls with the actual path and filename
' of the EXCEL file from which you will read the data
Set xlw = xlx.Workbooks.Open("C:\Filename.xls")
' Replace WorksheetName with the actual name of the worksheet
' in the EXCEL file
' (note that the worksheet must already be in the EXCEL file)
Set xlst = xlw.Worksheets("WorksheetName")
DoEvents
'--- Format code starts here
Set xlc = xlst.Range("C3:C10")
xlc.Interior.ColorIndex = 6
xlc.Interior.Pattern = xlSolid
Set xlc = xlst.Range("A29:K29")
xlc.Interior.ColorIndex = 6
xlc.Interior.Pattern = xlSolid
Set xlc = xlst.Range("K2:K47")
xlc.NumberFormat = "m/d/yyyy"
xlst.Range("A2").Select
DoEvents
'--- End Format code ----
' Close the EXCEL file, and clean up the EXCEL objects
xlw.Close True ' Save and close the EXCEL file
Set xlc = Nothing
Set xlst = Nothing
Set xlw = Nothing
DoEvents
If blnEXCEL = True Then
xlx.Quit
DoEvents
End If
Set xlx = Nothing
MsgBox "Done" 'I like to know when the routine is done
End Sub