application_newmail not running

  • Thread starter Thread starter James H
  • Start date Start date
J

James H

I just had a machine upgrade at work and now my VBA new
mail handler isn't running. Here's what I did to set it up:

1. Copy the code into a notepad file. Open the file on the
new machine, paste it into the Outlook session.

2. Use selfcert.exe to give the code a digital signature.

3. Set the macro security to medium.

4. Log out of Outlook, then relaunch. Outlook asks me if I
want to enable or disable macros. I say "enable."

From then on, I can run the macros manually (and they
work, so my code isn't at fault), but the new mail handler
never kicks in.

Here's the start of my code:

Dim WithEvents myOlApp As Outlook.Application

Sub Initialize_handler()
Set myOlApp = CreateObject("Outlook.application")
End Sub

Private Sub Application_NewMail()
Call DeleteOldContaining("Hourly Pendings")
Call DeleteOldContaining("Hourly Teams")
End Sub

.... any ideas? What step am I missing?

hjh
 
You don't need to instantiate an Outlook Application object in Outlook VBA
code, it's an intrinsic called Application. You also don't need a
WithEvents, those events are automatically provided for you.

If the project is signed you can trust that signature and you won't get the
macro prompts. To do so select Tools, Macro, Security. In that dialog you
should see your signature as a trusted source. If it's not there then use
Alt+F11 to open the VBA project and select Tools, Digital Signature, Choose
button. Select your signature and OK it. Then exit and restart Outlook. Then
your code should run on startup.
 
-----Original Message-----
You don't need to instantiate an Outlook Application object in Outlook VBA
code, it's an intrinsic called Application. You also don't need a
WithEvents, those events are automatically provided for
you.

OK, cool. Future optimization :)

I was fiddling with security settings this morning and
just discovered that the code is working now. I'll tighten
it back down and use your suggestion to make my signature
trusted.

Thanks.
hjh
 
Back
Top