On Open Macro

J

Jamie

I'm working in Word 2002 and have a macro that will run when the form is
open. The following coding works if the user opens the document in Word,
however if they open it through Explorer, the macro does not run.

Private Sub Document_Open()
Dim Msg, Style, Title, Response
Msg = "My message here."
Title = "Shift + Tab Key Error"
Response = MsgBox(Msg, Style, Title)
End Sub

Is there a way to get this to run whether the user opens the document in
Word or Explorer?
 
S

Shauna Kelly

Hi Jamie

Is this code in a document or in a template?

If it is in a template, bear in mind that the default action when you
double-click a file name in Windows Explorer is not to open a template, but
to create a new document based on that template. By contrast, the default
action for a document, is to open the document.

The way it's designed to work is as follows:
1. You create a template, and put the code in the template. Code in the
Document_Open event will run whenever a document based on that template is
opened.

2. Users fill in the form by doing File > New and selecting your template.
Or, they choose the template using Windows Explorer, and double-click the
name of the template (which will create a new document based on the
template).

If you want code to run whenever anyone creates a new document from the
template, use Private Sub Document_New().

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

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