View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Referencing CountA - Excel automation object not closing

Keith,
Also, what does .Range refer to here?...
"Befo=.Range("a" & r)"
Jim Cone


"archerokie"
wrote in message
Hi Jim, thanks for taking the time to help.

Why is it not advisable to use With construct? ActiveSheet? Selection?

As you can see I have tried to fully qualify the CountA method in these
lines. If I comment them out, the Excel object closes as expected. If I leave
these lines in the code, the Excel automation object remains open even after
the xlAPP.Quit and setting the variable = Nothing.
Do Until excel.Application.WorksheetFunction.CountA(xlSheet .Rows(r)) = 0
'inner loop
If excel.Application.WorksheetFunction.CountA(xlSheet .Rows(r)) < 0
Then r = r - 1
Loop 'inner loop
Debug.Print r & " = " &
excel.Application.WorksheetFunction.CountA(xlSheet .Rows(r))
If excel.Application.WorksheetFunction.CountA(xlSheet .Rows(r)) = 0
Then xlSheet.HPageBreaks.Add Befo=.Range("a" & r) '<<<<<<<<<<<<<<<<<<