Run a Script Rule doesn't work

lynxus

New Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
Hello,

first of all I hope this question hasn't been answered before and I'm in the right place here, been sitting on this problem for hours...

I am trying to run the script from this link together with a rule. The script works fine without the "Public Sub OpenLinks(olMail As Outlook.MailItem)" but without it, it doesn't show up in the script list when creating a rule. Everytime I try to run the code with "Public Sub" at the beginning nothing happens and a window pops up asking me to create a new macro (see attached picture).

I have the trust settings set to low and am running the code in a module, no other macros installed. Does anybody know how to solve this problem? Thanks in advance.
 

Attachments

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Did you Save the project? Sometimes the macros won't show up in run a script until you click Save in the VBA Editor.
None of the text is red?

paste this in the module and see if it shows up in the rules list. (It does nothing - i just want to see if it shows up.)
Code:
Public Sub TestMacro(olMail As Outlook.MailItem)
End Sub
 

lynxus

New Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
Thank you for your reply!

Your TestMacro does show up. Also I had saved my macro (with "Public Sub") and it shows up in the scripts lists, should have mentioned this in the start post. The problem is, that the macro does show up, but does nothing and can't be run via the green test button (asking me to create a new macro as in the picture) or when i send myself a test email. If i just start with "Sub OpenLinks()" it works flawlessly, but cannot be assigned to a rule (doesn't show up in the list).
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This part is required to use in a rule: olMail As Outlook.MailItem. olMail references the message and can be any variable - but it needs to match how the message is referenced in the code: If Reg1.test(olMail.Body) Then.

Oh... now i understand. Run a script rules aren't visible in the list of macros, only in the list when you set up a rule. You can't run them manually. I use a small stub macro to set the message (represented by olMail in this macro) so i can test it outside of a rule.

use this stub to run it manually - select a message and run this macro - it will call the openlinks macro and pass the selected message to it, just like a rule would do with an incoming message.

Code:
Sub RunScript()
Dim objApp As Outlook.Application
Dim objItem As MailItem
Set objApp = Application
Set objItem = objApp.ActiveExplorer.Selection.Item(1)

'macro name you want to run goes here
OpenLinks objItem

End Sub
 

lynxus

New Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
I'm a bit out of the loop now. Maybe it helps if i state what exactly i want to do (VBA newbie here).
My goal is to open all hyperlinks in new incoming unread emails automatically when they arrive in the folder. Therefore i tried to set up a rule, that starts the OpenLinks-Script everytime a new message arrives. Is this even possible?

I tried your RunScript but don't know exactly where to put it and what to do with it, I'm not a native speaker and have some trouble understanding the context. Once again thanks for your help though, maybe you got a (different) solution for what I'm trying to do!
 
Top