Message Box pop up before Open document

K

Kyle

Is there a way to have a message box pop up when the user
click to open a document. I like to have a message box pop
up with some message like this "The document you are about
to open contains..... Click OK to open document."

Thanks.
 
K

Kyle

I tried you suggestion. I couldn't make the message box
pop up before open the document. Instead the document
opened without the message box when user click the file to
open. I am using MSword 2K.
Thanks.
-----Original Message-----
Hi Kyle

Assuming you have a recent-ish version of Word, here are the steps:

1. Open the document.
2. Alt-F11 to open the Visual Basic Editor.
3. View > Project Explorer.
4. On the left, you'll see a list of files including
something like Project (your document name). Double-click
it.
5. Under Microsoft Word objects, double-click on ThisDocument.
6. You'll see a code area open up on the right.
7. If the code area does not already say Option Explicit,
then type that and press Enter.
8. Paste the following code below the "Option Explicit" text.
9. Save your document, close it and re-open to test the code.

Private Sub Document_Open()

If MsgBox(Prompt:="The document you are about to open " _
& "contains ..... . " _
& "Click OK to open document.", _
Buttons:=vbOKCancel) = vbCancel Then
Me.Close
End If

End Sub

The code above will work in a document, but it will fire
the macro security warning every time the document is
opened (assuming that
Tools > Options > Security > Macro Security is set to
Medium, which is where most people put it). If you want to
avoid firing the
macro security warning, then you need to put the code
above into a Template, and base your documents on that
template.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top