Word 2003 Application Event running first in Outlook 2003

V

VlnChemE

I am trying to have a macro run (updates all fields when I save, open, or
print any document. The way I found to accomplish this was through
Application Events (see
http://word.mvps.org/FAQs/MacrosVBA/AppClassEvents.htm) such as
DocumentBeforeSave and DocumentBeforePrint. I put the following code in a
class module called ThisApplication in a global add-in (located in the
STARTUP folder)

Option Explicit

Public WithEvents oApp As Word.Application

Private Sub oApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As
Boolean, Cancel As Boolean)
MsgBox "Hello, I am before save"
End Sub

The following code is in Moldule1:

Option Explicit

Dim oAppClass As New ThisApplication

Public Sub AutoExec() 'Note AutoOpen does not fix
the prob
Set oAppClass.oApp = Word.Application
End Sub

As I understand it, the AutoExec runs when Word starts which will put my
DocumentBefore* events into play.

This words beautifully if I open Word BEFORE Outlook (which is using Word as
my editor and I would rather keep it that way). If I open Word AFTER already
opening Outlook, it does not work. If I manually run the AutoExec macro it
does though.

I would like to make my Application Events work ALL of the time, regardless
of if I open up Word 1st or Outlook 1st. Any suggestions are welcome.

Thank you.
 
D

Doug Robbins - Word MVP

Sorry, that is the way it is and I don't think that there is anyway around
it.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
O

old man

Outllok starts Word when it starts. To see this close all copies of Word and
Outlook. Open Task Manager and click on the Processes Tab. Sort the processes
by clicking on the top of the column titled Image Name to sort it. Notice
that word (Winword.exe) is not running.

Now start Outlook and switch back to the Task Manager and the Processes
Window. You will now see Winword.exe in the list. Your template is probably
loaded and has executed.

old man
 

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