Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBA keep word document open

Posted on 2004-03-22
2
Medium Priority
?
426 Views
Last Modified: 2008-03-06
I need some code for a MS Word macro that will keep a document from closing until certain fields are filled out. I can trap the field state (clean/dirty) I just need a way to keep word from closing. This has to work in any circumstances. Whether the user closes just the active document or closes word all together. Also needs to work in Word 2000, XP, and 2003.
0
Comment
Question by:mnorma12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 375 total points
ID: 10652722
This works in Word 2000. I haven't got the other two

In a module in you template, put this code:

Dim mdlEvClass As New Class1
Sub AutoOpen()
Register_Event_Handler
End Sub
Sub AutoNew()
Register_Event_Handler
End Sub
Sub Register_Event_Handler()
    Set mdlEvClass.App = Word.Application
End Sub
Sub Autoexec()
Register_Event_Handler
End Sub

Put this code in a class module called 'Class1'

Public WithEvents App As Word.Application

Private Sub App_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
'Replace the MsgBox question with your document test
If MsgBox("Do you want to close this document", vbYesNo) = vbNo Then
    Cancel = True
End If
End Sub

0
 

Author Comment

by:mnorma12
ID: 10656679
This works well. Maybe too well. Once I get this in there i can no longer close my template. I'll work around it.

Thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question