Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA 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 11th, 2005, 09:47 AM
Registered User
 
Join Date: Jan 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Closing word hidden instances

I'm trying to find a way to check if there's any Word instance running in the background, and if so, close it/them.
Does anybody know how to do it?

Thanks very much for your help.

 
Old January 11th, 2005, 10:53 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

This will close all open instances.

'Set reference to Microsoft Word x.0 Library

Sub CloseWord()

    Dim WordApp As Word.Application

    Const ERR_APP_NOTRUNNING As Long = 429

    On Error Resume Next

    Set WordApp = GetObject(, "Word.Application")

    ' If no instances running, exit sub.
    If Err = ERR_APP_NOTRUNNING Then
        Exit Sub
    Else
        WordApp.Quit
        Set WordApp = Nothing
    End If

End Sub

HTH,

Bob

 
Old April 13th, 2007, 03:04 PM
Registered User
 
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Another option is to just avoid getting multiple background instances running (one is OK as far as I'm concerned).

Here's a snippet I find handy:

On Error Resume Next
    ' Dim apWord As Word.Application ' declare here or higher in scope
    Set apWord = GetObject(, "Word.Application")
    If Err = 429 Then Set apWord = New Word.Application
On Error GoTo Local_Err
...
Local_exit:
    Set apWord = Nothing

This code will try to use a running instance and if it fails create one.

You can show your instance:
    apWord.ActiveWindow.Visible = True

Not sure how you can easily force it to the top using apWord - if someone knows please post here.

BTW if you use Quit you may kill a session being shared with the desktop.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How many Instances are running dash dev C# 2005 7 December 5th, 2007 04:05 PM
different instances of a same database(Urgent) JustALearner BOOK: Professional SQL Server 2005 Reporting Services ISBN: 0-7645-8497-9 0 July 12th, 2007 02:32 AM
InStr() repeat instances spinout Classic ASP Components 7 November 23rd, 2006 11:55 AM
Running 2 instances of tomcat steevo590 Apache Tomcat 0 April 5th, 2006 12:53 PM
Preventing new instances of the same application aehb C# 3 May 18th, 2005 01:14 PM





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