This code runs okay, but I cannot quit Excel. I've read that this may be
due to the way I reference the object variables, but I don't know how else I
would reference them. How do I get Excel to quit gracefully?
Thanks in advance.
Set xlapp = GetObject(, "Excel.Application")
'create new on error if none exists
Set xlwkb = xlapp.Workbooks.Open(strTarget)
For Each fldSub In fld.SubFolders
strSheetName = fldSub.Name
strMdb = fld & "\" & strSheetName
If LinkTable(strMdb) Then
j = xlwkb.Worksheets.Count
xlwkb.Worksheets.Add(After:=Worksheets(j)).Name = strSheetName
'DoCmd.TransferSpreadsheet transferType:=acExport,
queryname:="qryMean", fileName:=strTarget
'DoCmd.TransferSpreadsheet acExport, 8, "qryMean", strTarget,
True
bytWsCt = bytWsCt + 1
xlwkb.Save
End If
Next fldSub
xlapp.Quit ********* 'why doesn't this work?
Select Case Err.Number
Case 429
Set xlapp = CreateObject("Excel.Application")
Resume Next