Word

Collapse Word's window upwards, then exit.

Ease of Use

Easy

Version tested with

2000, 2002, 2003 

Submitted by:

Marcster

Description:

This example will slowly roll up Word's window then exit Word. 

Discussion:

This example will slowly exit Word differently to the usual default way. It will roll up Word's window, displaying a more impressive way to exit Word. It uses the API function AnimateWindow to do this. You could use this as a novel way to exit Word. 

Code:

instructions for use

			

Option Explicit Private Declare Function AnimateWindow Lib "USER32" (ByVal hWnd As Long, ByVal _ dwTime As Long, ByVal dwFlags As Long) As Boolean Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal _ lpClassName As String, ByVal lpWindowName As String) As Long Const AW_HIDE = &H10000 'Hide Const AW_SLIDE = &H40000 'Slide animation. Const AW_VER_NEGATIVE = &H8 'Animates Word from bottom to top. Private Sub Document_Close() Dim lngFrmWindow As Long 'Retrieve a handle to Word 'OpusApp is the Class name for Word 2000/2002 'ActiveDocument.Name & " - " & Application.Name 'retrieves Word's window title text, this is what we need lngFrmWindow = FindWindow("OpusApp", ActiveDocument.Name & " - " & Application.Name) If lngFrmWindow <> 0 Then 'lngFrmWindow returns a zero if there's an error 'Make Word roll upwards and exit '750 is in milliseconds the time length of the animation AnimateWindow lngFrmWindow, 750, AW_SLIDE Or AW_VER_NEGATIVE Or AW_HIDE Else 'An error has occured with the AnimateWindow function Call MsgBox("There was an error when trying to animate the Word window." _ & vbCrLf & "" _ , vbCritical, Application.Name) End If 'Quit Word Application.Quit End Sub

How to use:

  1. Open Word.
  2. Alt + F11 to open the VBE.
  3. Paste the code from above into the ThisDocument module.
  4. Close the VBE (Alt + Q or press the X in the top right corner).
  5. Save.
  6. Exit Word.
 

Test the code:

  1. Open the attached document.
  2. Exit Word.
 

Sample File:

SlideExitWord.zip 6.02KB 

Approved by mdmackillop


This entry has been viewed 88 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express