PDA

View Full Version : Getting script to fire in Outlook 2003 ...



vodkasoda
10-12-2009, 08:46 AM
I've just rebuilt my windows Vista system, due to numerous space & performance problems. This is not normally a problem, as the only thing that I have on my C: drive is Windows, everything else is on other drives, it's just a matter of doing a few updates & re-installs to rebuild the Registry.

Therefore, having re-installed Office 2003, I've got my Macros back in place and they all run if I invoke them, but the main one, which used to trigger every time I got a new E:Mail is not firing automatically ... I am assuming I've forgotten to do something, or I've done something wrong ... please help !!!

I have the following code in a ClassModule, ThisOutlookSession1, but it doesn't fire :

Sub Application_NewMailEx(ByVal EntryIDCollection As String)

Call MyRules
Call ValidateKATurns
Call KATurns

End Sub

I have no idea if this is relevant, but under the Properties for ThisOutlookSession1 is a single entry, Instancing, with the value 2 - PublicNotCreatable

Also, just as background ... when I open VBA, the tree on the left hand side of the screen says :

Project1(VbaProject.OTM)

Microsoft Office Outlook Objects

ThisOutlookSession (this is empty)
Forms

KA_Files_Received
Modules

Definitions
KA_Turns
My_Rules
Validate_KA_Turns
Class Modules

ThisOutlookSession1 (this contains the aforementioned code)

Thanks in advance for any help ...

JP2112
10-14-2009, 10:25 AM
Since your code isn't in the default 'ThisOutlookSession' module, you need to tell Outlook it's there. In ThisOutlookSession, you need something like

Private WithEvents olApp As Outlook.Application
Private Sub Application_Startup()
Set olApp = Application
End Sub

Then in ThisOutlookSession1, change Application to olApp. Although personally I would place all the event handlers in ThisOutlookSession to avoid having to set up new classes.

FYI- after installing or changing any event handlers, Outlook must be restarted.

--JP

vodkasoda
10-15-2009, 01:05 AM
... I have to do the school runs, then I'll give this a try ... however, bearing in mind that though I am a programmer, but NOT a VB programmer, have you any idea why I might have done it like this in the first place ?!? I will have been told to do it like this, I don't even know what "classes" are or what significance they hold !!!

Can I simply move the stuff from ThisOutlookSession1 to ThisOutlookSession ?

Thanks again ...

Gaz



Since your code isn't in the default 'ThisOutlookSession' module, you need to tell Outlook it's there. In ThisOutlookSession, you need something like

Private WithEvents olApp As Outlook.Application
Private Sub Application_Startup()
Set olApp = Application
End Sub

Then in ThisOutlookSession1, change Application to olApp. Although personally I would place all the event handlers in ThisOutlookSession to avoid having to set up new classes.

FYI- after installing or changing any event handlers, Outlook must be restarted.

--JP

JP2112
10-15-2009, 04:05 AM
If you move your existing code to ThisOutlookSession, it should work.

vodkasoda
10-15-2009, 09:49 AM
It did indeed, thanks for your help ...


If you move your existing code to ThisOutlookSession, it should work.