Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 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 August 26th, 2003, 04:22 PM
Registered User
 
Join Date: Aug 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Detect status of Word

I have a VB application that launches Word. It must then wait for the user to close Word. I can't seem to detect when Word is closed (or hang while Word is open).

I have tried getting the exit code from the OpenProcess function. When I do that Word appears to open and close immediately (if you already have one instance of word running). If you run the following code when there is already one instance of Word running, the message box fires immediately after the new instance of Word loads

Code:
   Dim ProcessId&
   Dim hProcess&
   Dim ExitCode&
   ProcessId = Shell("C:\PROGRA~1\MICROS~3\Office10\WINWORD.EXE", vbNormalFocus)
   hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)
   Do
      Call GetExitCodeProcess(hProcess, ExitCode)
      DoEvents
   Loop While (ExitCode = STILL_ACTIVE)
   Call CloseHandle(hProcess)
   MsgBox "Word was closed"
Help???

 - Jerome
 
Old August 28th, 2003, 12:31 PM
Authorized User
 
Join Date: Aug 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Jerome,

VB doesn't have to wait for Word to be closed — because it can simply hook into the currently active Word program. Actually, once you've included a reference to Word (under Project | References) -- you should use code similar to that shown below --

Code:
Dim WordApp As Object
On Error GoTo APPLICATION_CREATE            ' An error will cause us to initiate the Appl.
Set WordApp = GetObject(, "Word.Application") ' Obtaining ref to active app
GoTo SKIP_APPLICATION_CREATE                ' Of course if it's already there, then we'll use that
APPLICATION_CREATE:
Set WordApp = CreateObject("Word.Application")
SKIP_APPLICATION_CREATE:
On Error GoTo BYE            ' Back to our normal way of life
For more info relating to automation, see the code snippets at http://www.vba-programmer.com

CarlR







Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating word doc - word behaviour mat41 Classic ASP Professional 2 April 29th, 2007 06:46 PM
Status Bar ironchef Java GUI 0 October 26th, 2006 09:19 PM
Status Box jbenson001 ASP.NET 1.x and 2.0 Application Design 7 May 10th, 2004 03:32 PM
Copy word to word doc. in VB vamshi Pro VB 6 1 March 24th, 2004 06:25 PM
Status Bar soccers_guy10 Pro VB.NET 2002/2003 3 August 12th, 2003 11:48 PM





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