Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

On Exit

Status
Not open for further replies.

daybase

Technical User
Dec 13, 2002
115
GB
Is it possible to apply an On Exit event to Microsoft word document?
 
Hi daybase,

You need an AutoClose macro. Just name a macro AutoClose and it should run - scope will depend on where you put it. If it's in a document it should only run when that document is closed. if it's in your Normal template it will run when most any document is closed.

Enjoy,
Tony
 
Thanks for that - is that a macro in word? How about if I want to trigger Access VBA code when I close or exit a word document?
 
Hi daybase,

Yes, that's a macro in Word. From it you can do (more or less) what you want. If you add the following to the ThisDocument code module (under Microsoft Word Objects in your document) it will run a VBA routine in an Access Database when you close your document:

Code:
Sub AutoClose()

Dim appAccess As Access.Application

Set appAccess = CreateObject("Access.Application")

With appAccess
    .OpenCurrentDatabase "
Code:
D:\My Documents\db3.mdb
Code:
"
    .Run "
Code:
myPublicSubInAccessDatabase
Code:
"
    .CloseCurrentDatabase
    .Quit
End With

Set appAccess = Nothing

End Sub

(changing my names for yours, of course)

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top