Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 13th, 2005, 05:45 AM
Authorized User
Join Date: Jun 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Kill Excel after printing completed

I have written an application that uses an Excel template to print as follows, after populating the spreadsheet:

  'print the active sheet
  objWks.PrintOut Copies:=dblNumCopies, Collate:=True
  objWkb.Close SaveChanges:=False
  'close the objects
  Set objExcel = Nothing
  Set objWkb = Nothing
  Set objWks = Nothing

I have found however that the EXCEL object does not close when checking taskmanager. I assume that this is because the printer is busy with the sheet even after I have closed it. After the printing completed nothing closes the EXCEL object as my code has run already and the object stays open.

Is there any way that I can have my application wait on the printin to be completed before I close the object. I have tried looking at API calls to try and figure this out but the challange is to ask the printer for a message that my specific print job is completed. (This is because the printing is sent to a network printer where more than one person could be printing.

Please help.
Old January 13th, 2005, 09:12 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG

Have you tried doing this first?


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
Old January 13th, 2005, 10:19 AM
Authorized User
Join Date: Jun 2003
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts

I have declared obj Excel as follows

   Set objExcel = New Excel.Application

It unfortunately does not have a .Close parameter. Thanks for your suggestion though!

Any other thoughts?

Old June 15th, 2006, 11:02 AM
Registered User
Join Date: Jun 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

See "50 Ways to Kill Excel"
Old June 15th, 2006, 04:17 PM
Friend of Wrox
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts

There was a bug regarding using Word that was similar to this. There was also a very specific work-around, though I forget what that work-around was.

I have this niggling remnant of a memory that is was something like: after closing Word, using GetObject() to obtain a reference to that instance that ought not to be there, and again invoking the command to close the app.
Old June 26th, 2006, 07:13 AM
Friend of Wrox
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts

I thought it was:

objExcel.Quit(false) (The false suppresses the save dialogue)


Similar Threads
Thread Thread Starter Forum Replies Last Post
coding for printing in excel ct Excel VBA 3 August 8th, 2005 08:05 AM
Printing excel sheet siddique Excel VBA 3 February 15th, 2005 12:49 AM
Printing using EXCEL object Bruce Pro VB 6 0 January 14th, 2005 10:11 AM
Printing Excel File in ASP hkccwong Classic ASP Basics 1 January 5th, 2005 12:50 AM
export excel file and printing yyjfree Crystal Reports 0 December 13th, 2004 02:44 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.