Autoexec to keep running

R

richard.jolly

Dear all

I'm fairly new to class modules - but i'm ok with vba and regular
events.

I have a number of routines in modules that I want to run when the
document is changed. So far I have the following:

In Normal.dot template module

Option Explicit

Dim oAppClass As New ThisApplication
Dim strDocName As String
Dim strRefDoc As String

Public Sub AutoExec()
Set oAppClass.oApp = Word.Application
End Sub

plus....other modules below!

In Normal.dot template a Class module called ThisApplication:

Option Explicit

Public WithEvents oApp As Word.Application


Private Sub oApp_WindowActivate(ByVal Doc As Document, ByVal Wn As
Window)
ExtractDocNameRef
End Sub

ExtractDocNameRef is the name of the routine I want to run (does this
need to be in actual doc (let me call it TEST.DOC) or does it have to
be in a standard module in Normal.dot template)?

Anyhow - Auto exec fires when I boot up the Any document (really I only
want is to fire when I open TEST.DOC

Also when I change TEST.DOC the fires -good. However if I open a blank
doc, it will fire for that document.

Also once it has fired for Test doc, it will not fire again, if I make
subsequent changes.

Sorry it is a little jumbled. If it helps I can post all the routines
and try and specify what I'm trying to acheive. But for now I'm just
trying to better understand how the document change event works.

Thanks

Richard J
Nottingham UK
 
J

Jonathan West

Hi Richard

Take a look at these articles

How to create global event procedures similar to AutoOpen, AutoNew and
AutoClose, without using Normal.dot
http://www.word.mvps.org/FAQs/MacrosVBA/PseudoAutoMacros.htm

Running a macro automatically when a document is created, opened or closed
http://www.word.mvps.org/FAQs/MacrosVBA/DocumentEvents.htm

Writing application event procedures
http://www.word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm

If they don't answer your questions fully, by all means come back and ask
some more.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
C

Cindy M -WordMVP-

I'm fairly new to class modules - but i'm ok with vba and regular
If code should execute only when a certain document opens then it should
be in the DocumentOpen procedure of the ThisDocument class *in that
document*.

AutoExec is used for code that should execute when Word is started.
I have a number of routines in modules that I want to run when the
document is changed. So far I have the following:

In Normal.dot template module

Option Explicit

Dim oAppClass As New ThisApplication
Dim strDocName As String
Dim strRefDoc As String

Public Sub AutoExec()
Set oAppClass.oApp = Word.Application
End Sub

plus....other modules below!

In Normal.dot template a Class module called ThisApplication:

Option Explicit

Public WithEvents oApp As Word.Application


Private Sub oApp_WindowActivate(ByVal Doc As Document, ByVal Wn As
Window)
ExtractDocNameRef
End Sub

ExtractDocNameRef is the name of the routine I want to run (does this
need to be in actual doc (let me call it TEST.DOC) or does it have to
be in a standard module in Normal.dot template)?

Anyhow - Auto exec fires when I boot up the Any document (really I only
want is to fire when I open TEST.DOC

Also when I change TEST.DOC the fires -good. However if I open a blank
doc, it will fire for that document.

Also once it has fired for Test doc, it will not fire again, if I make
subsequent changes.

Sorry it is a little jumbled. If it helps I can post all the routines
and try and specify what I'm trying to acheive. But for now I'm just
trying to better understand how the document change event works.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
R

richard.jolly

Thanks Guys

I guess I need to hit the books on this subject. I suppose I've a
classic mistake of writing all the routines THEN deciding what the
events are that trigger it. In my naviety I guessed the event bit would
be easy!!

Cheers

Richard
 

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