Outlook rule run a Script doesn't work

Status
Not open for further replies.

bibitux

New Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
hello everyone,
Sorry for my english.
i found the script to change the subject of mails. The script runs over a rule. Unfortunately the script only works in an email where it is active.
I have 10 emails in a test folder. Rest of the mails does not work.
I chose by rule: Apply rule to all messages.
Can someone help me find out why the rest of the emails don't work.
Thank you.

Public Sub EditSubject(Mail As Outlook.MailItem)
Dim Item As Outlook.MailItem
Dim oInspector As Inspector
Dim strSubject As String
Dim strPrefixSubject As String

Set oInspector = Application.ActiveInspector

If oInspector Is Nothing Then
Set Item = Application.ActiveExplorer.Selection.Item(1)
Else
Set Item = oInspector.CurrentItem
End If

strSubject = "AW: "

Debug.Print Item.subject

Item.subject = Replace(Item.subject, strSubject, "", vbTextCompare)
Item.Save

' Prefix subject with Confidential and Legally Privileged
strPrefixSubject = "" & Item.subject

' Set the message subject
Item.subject = strPrefixSubject
Item.Save


Set Item = Nothing
Set oInspector = Nothing

End Sub
 
This line:
Set Item = Application.ActiveExplorer.Selection.Item(1)
Says use it on the selected message.

Remove this entire block - it applies to open or selected messages, not to new messages arriving
Set oInspector = Application.ActiveInspector

If oInspector Is Nothing Then
Set Item = Application.ActiveExplorer.Selection.Item(1)
Else
Set Item = oInspector.CurrentItem
End If


Change Mail to Item in the first line and delete these two Dim lines
Public Sub EditSubject(Mail As Outlook.MailItem)
Dim Item As Outlook.MailItem
Dim oInspector As Inspector


Delete this line - Set oInspector = Nothing


Code:
Public Sub EditSubject(Item As Outlook.MailItem)
Dim strSubject As String
Dim strPrefixSubject As String

strSubject = "AW: "

Debug.Print Item.subject

Item.subject = Replace(Item.subject, strSubject, "", vbTextCompare)
Item.Save

' Prefix subject with Confidential and Legally Privileged
strPrefixSubject = "" & Item.subject

' Set the message subject
Item.subject = strPrefixSubject
Item.Save

Set Item = Nothing
End Sub
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
O Outlook 2016 This rule will only run when you check your email in Outlook.... Using Outlook 4
Gary Brown Outlook 2013 VBA to run a rule Outlook VBA and Custom Forms 13
J outlook rule doesn't run automatically Using Outlook 0
D Create a macro in Outlook to run a rule Outlook VBA and Custom Forms 32
P VBA to add email address to Outlook 365 rule Outlook VBA and Custom Forms 0
HarvMan Outlook 365 - Rule to Move an Incoming Message to Another Folder Using Outlook 4
B Seeking help with Outlook rule Using Outlook 2
R Rogue Outlook Rule ? Using Outlook 2
T "Words In Recipient's Address" Rule Causes Outlook To Stop Processing Rules Using Outlook 3
R Outlook Autoforward rule do not work for NDR messages Using Outlook 1
R Setup autofoward rule on a particular folder in Outlook Using Outlook 0
S Unable to remove rule outlook 2010 Using Outlook 0
N Outlook Email Rule execution through shortcut keys (VBA codes) Using Outlook 1
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
S Adding new Exchange (2016) rule very slow down Microsoft Outlook Exchange Server Administration 0
A Forward Outlook Email by Filtering using Macro Rule Outlook VBA and Custom Forms 44
J Outlook Rules - Changing auto-submit address in multiple rules, according to rule name Outlook VBA and Custom Forms 0
Liza Creating a rule in outlook to filter messages Using Outlook 0
T Create Rule For Secondary E-Mail Address In Outlook 2016 Using Outlook 4
A Creating an outlook rule to forward an email with a specific message Using Outlook 1
S using script rule to save attachments on arrival Outlook 2010 Outlook VBA and Custom Forms 9
I outlook rule keywords based on list Using Outlook 0
M Outlook 2016 Desktop - Automatic Rule Processing Using Outlook 3
I Create custom Outlook 2013 Rule in Office 365 Outlook VBA and Custom Forms 5
K Outlook moves sender's mail, but there is no rule Using Outlook 0
J Outlook creating unwanted rule on its own Using Outlook 1
F Outlook rule, specific words, not specific words Using Outlook 1
R Outlook 2013 VB rule to auto save attachments with different file types Outlook VBA and Custom Forms 5
Mary B Outlook 2013: Rule for copying new email to folder & marking that copy as read Using Outlook 1
J Outlook Rule - Create Link in Forwarding Message Outlook VBA and Custom Forms 2
B Outlook 2000 Rule to Move txt msg Not Working if size >24KB Using Outlook 3
G Creating an Outlook Rule using Internet Header time Using Outlook 1
N rule to move sent mail to the deleted folder in outlook Using Outlook 4
M Outlook Rule To Redirect Mail - Script to overcome lack of cc's & others Using Outlook 0
S Outlook VBA rule script to process both MailItem and MeetingItem Using Outlook 0
K Implementing an AND logic rule in OUTLOOK Using Outlook 1
C Outlook rule moves e-mail to a deleted folder Using Outlook 1
E Outlook rule only active certain times of day Using Outlook 6
W Outlook sent to "person" rule excluding cc Using Outlook 2
D Private messages not forwarding by rule? Outlook 2007 Using Outlook 1
F Outlook Rule using message header not working Using Outlook 2
M Outlook 2003 rule to detect a blank category Using Outlook 1
J Create or Import a Outlook Rule through C# code. Outlook VBA and Custom Forms 2
G Outlook rule check for messages not received Outlook VBA and Custom Forms 2
N How to create hidden rule in outlook 2007 Outlook VBA and Custom Forms 3
T forcing a rule when opening outlook via code Outlook VBA and Custom Forms 1
N Outlook alert/memo/rule when an email does not arrive Using Outlook 3
R Outlook 2003/2007 Rule and Conditions for InBox VBA customization Outlook VBA and Custom Forms 3
K Re: Cuestom outlook rule using vba Outlook VBA and Custom Forms 4
A Outlook can't remember outlook.com, Exchange password. Using Outlook 0

Similar threads

Back
Top