Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel does not close from VB!! (when i refresh Refresh query with BackgroundQuery:=False)

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

(relevent section of code)

Sub Main()
Dim xlApp As Object
Dim myDate As Date
Set xlApp = CreateObject("Excel.Application")

xlApp.Visible = True
xlApp.DisplayAlerts = True
xlApp.Workbooks.Open ("D:\bin\mySheet.xls")
xlApp.Sheets("myfirst").QueryTables(1).Refresh BackgroundQuery:=False
xlApp.Sheets("mysecond").QueryTables(1).Refresh BackgroundQuery:=False
'xlApp.Application.ActiveWorkbook.PrintOut Copies:=1, Collate:=True

myDate = xlApp.Sheets("myfirst").Range("B12").Value
xlApp.Workbooks("JGBAnalytics.xls").Close True

xlApp.Quit
Set xlApp = Nothing
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I 'Enable Automatic Refresh' for Query Refresh by default Anand Deshpande Setting up and Configuration of Excel 0 December 10th 06 04:47 AM
save & close after web query refresh JVLin Excel Discussion (Misc queries) 0 September 28th 05 04:27 PM
Problems with .Refresh BackgroundQuery:=False dmplacebo Excel Worksheet Functions 0 July 11th 05 12:39 PM
Query Refresh-Enable Automatic Refresh Dialogue Box Terri Excel Discussion (Misc queries) 0 May 6th 05 08:21 PM
Web Query fail to Refresh All but individual refresh is ok Karyn Mak Excel Programming 2 July 17th 03 09:30 AM


All times are GMT +1. The time now is 05:15 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"