View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Heiko Heiko is offline
external usenet poster
 
Posts: 16
Default Excel does not close from VB!! (when i refresh Refresh query with BackgroundQuery:=False)

Hello Anant
try to use the method as a Function like

Sub Main()
Dim lngRet As Long
Dim xlApp As Object
Dim myDate As Date
Set xlApp = CreateObject("Excel.Application")
With xlApp
.Visible = True
.DisplayAlerts = True
.Workbooks.Open ("D:\Mappe1.xls")
lngRet =
Sheets("myfirst").QueryTables(1).Refresh(Backgroun dQuery:=False)
If Not lngRet Then
' Error - Handling
End If
lngRet =
Sheets("mysecond").QueryTables(1).Refresh(Backgrou ndQuery:=False)
If Not lngRet Then
' Error - Handling
End If
'.Application.ActiveWorkbook.PrintOut Copies:=1, Collate:=True
'Sheet has been changed so perhaps
'.Application.ActiveWorkbook.Close False
myDate = .Sheets("myfirst").Range("B12").Value
.Workbooks("JGBAnalytics.xls").Close True
.Quit
End With
Set xlApp = Nothing
End Sub

Heiko
:-)
(Anant) wrote:

Dear all,
I desperately need help. I have been working on this Excel automation
from VB. The task involves launching a set of Excel Addins, workbooks,
printing them and shutting everything down. All my workbooks shut down
with the usual quitting the excel object and setting it nothing,
except this one workbook. This workbook doesnt let excel shutdown
keeps lurking in my Task Manager. I traced the reason to one line of
code

xlApp.Sheets("myfirst").QueryTables(1).Refresh BackgroundQuery:=False

when i comment this out every thing shuts down. but i need the queires
refreshed before i print. I looked at what people had suggested for
this problem and specifically defined objects for workbook, worksheet,
querytable and once i was done with them set them to nothing. That
didnt work. im certain im missing something. Please please

regards,
Anant

<SNIP