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.
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.