| re: Automation - xlapp.Quit does not kill Excel
This line:
xlwkb.Worksheets.Add(After:=Worksheets(j)).Name =
strSheetName
is creating a new reference because you're not fully declaring the
Worksheets(j) to be a property of xlwkb object.
Try this:
xlwkb.Worksheets.Add(After:=xlwkb.Worksheets(j)).N ame =
strSheetName
By the way, I have never seen syntax of
.Name = strSheetName
at the end of a Worksheets.Add method. Is this a copy/paste error?
--
Ken Snell
<MS ACCESS MVP>
"deko" <deko@hotmail.com> wrote in message
news:iX3Ud.9681$Pz7.6299@newssvr13.news.prodigy.co m...[color=blue]
> 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
>
>[/color] |