Can't get document events to trigger

J

Jim Burke in Novi

Help! I'm an experienced vba programmer in access, and cannot for the life of
me figure out how to get simple events to trigger in word. All I want is for
a sub to run whenever a doc is opened. I tried Document_Open and
Document_New, I tried creating an AutoExec macro, but whenver I open a test
doc nothing happens. Can someone please tell what the secret is? I've wasted
much too much time on this seemingly ridiculously simple task!! Any help is
appreciated.

Note: I originally put a command button on the doc (via the control
toolbox), which would trigger it's event when the user clicked it. Simple
enough, you would think. That worked on first try, but whenever I closed and
reopened the doc the button no longer worked. After doing some research, it
seems like using the controls from the control toolbox is a no-no. I am
mystified by Word's VBA rules!

Jim B
 
G

Gordon Bentley-Mix

Jim,

Check out the VBA help topic on Auto Macros. I think maybe what you're
looking for is an AutoOpen macro. AutoOpen macros run whenever a document
containing the macro (or a document based on a template containing the macro
- provided the user has access to the template) is opened. To use one either:
* Create a module called AutoOpen and write a procedure in this module
called "Main" or
* Write a procedure in any module called "AutoOpen"
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
F

fumei via OfficeKB.com

"I tried Document_Open and
Document_New, I tried creating an AutoExec macro, but whenver I open a test
doc nothing happens. "

Are you sure you are using Document_Open in the correct project?

I have never had a document, any document, that had a Document_Open event in
the correct module (ThisDocument) not work.

"After doing some research, it seems like using the controls from the control
toolbox is a no-no. "

I am not sure what you mean by that, that is, what research would come to
that conclusion. I use controls from the Controls toolbar all the time, and
I have no problem getting event procedures to fire.

Just put the control into the document, right click it, select View Code, and
write the code.

Now, it is true, as Controls are ActiveX there can be security issues. If
security is set for High, they will not work.
 
G

Gordon Bentley-Mix

After I submitted my post, the thought occurred to me that this might just be
a security issue. A security setting (Tools | Macro | Security...) of High or
Very High might also prevent a Document_Open or even an AutoOpen macro from
running.
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 

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