# Outlook VBA, Macros not appearing in "Run a script" menu



## bamblack (Apr 16, 2012)

Hi all,

I've written a bit of code:


```
Option Explicit
Sub Run(msg As MailItem)

'Miscellaneous code here

End Sub
```

However, when I try to set up a rule so that it will run this code when a certain email is received, the subroutine isn't showing up in the "Run a script" menu. I have the code saved in it's own standard module. I've been trying to figure it out for the past hour or so and haven't been able to make any headway on it. I'm just jumping into Outlook VBA, so any suggestions on how to fix it would be greatly appreciated!


----------



## RoryA (Apr 16, 2012)

If I add that code to a module it appears in the list when I click the Script link in the Rules Wizard. Which version of Outlook?


----------



## bamblack (Apr 16, 2012)

Outlook '07. I've also double checked my macro security to make sure they're enabled.


----------



## RoryA (Apr 16, 2012)

Curious. It works fine in 2010. I'll see if it's a known issue.


----------



## bamblack (Apr 16, 2012)

Also something that may be of note, none of the modules I've written are appearing in the Run menu when I press F5 inside the VBE. However, if I write a test module and just say


```
Sub Run

'Code Here

End Sub
```

It shows up fine in the VBE Run menu, but not in the Run a script menu. I'm really going loopy over here trying to figure this one out.


----------



## RoryA (Apr 16, 2012)

The procedure declaration has to be specific (taking a mailitem or appointmentitem argument) for the procedure to appear in the run a script section.
Wild thought - you haven't used the same name for the module as you did for the routine?


----------



## bamblack (Apr 16, 2012)

Nope, different names for module/sub. And I remember reading that somewhere, I just figured it had to be there to appear in either. I've even gone to the point of running Office Diagnostics, but it didn't find anything.


----------



## bamblack (Apr 16, 2012)

I figured it out, when you said same name for module/routine, it got me to thinking. I have two modules, each with one sub and both subs were named "Run". I changed the name of one of them and voila, they appeared!


----------



## DBA999 (Apr 18, 2012)

Having the same problem but not for the same reason apparently. In the VBA IDE I have 2 modules, module1 & module2. They each have differently named subroutines which use type MailItem. If I go into rules in Outlook both the subroutines show up. But if I press F5 in the IDE or select Tools, Macros from the menu, they are not listed even though even though the Project listed in the “Project In” box is correct. Very frustrating. Help very appreciated.  Thanks!


----------



## RoryA (Apr 18, 2012)

You can't run a macro that requires arguments using f5, and they won't appear in the macro dialog box, since neither method would allow you to pass a mailitem to the routine.


----------



## bamblack (Apr 16, 2012)

Hi all,

I've written a bit of code:


```
Option Explicit
Sub Run(msg As MailItem)

'Miscellaneous code here

End Sub
```

However, when I try to set up a rule so that it will run this code when a certain email is received, the subroutine isn't showing up in the "Run a script" menu. I have the code saved in it's own standard module. I've been trying to figure it out for the past hour or so and haven't been able to make any headway on it. I'm just jumping into Outlook VBA, so any suggestions on how to fix it would be greatly appreciated!


----------



## DBA999 (Apr 18, 2012)

Good to know. Thanks. Sure makes de-bugging a pain....


----------



## RoryA (Apr 19, 2012)

You can either add breakpoints, or create a test sub that calls your processing sub.


----------

