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
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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.
Thread starter Similar threads 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
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
R Outlook 2010 rule not recognizing inbound meeting requests Using Outlook 4
1 Outlook's Rules Wizard; No 'Forward using a specific template' Rule Using Outlook 4
williamlambton Setting up a Rule for Hotmail using Outlook 2007. Using Outlook 1
O Outlook 2010: Rule to move sent emails doesn't start if I Use "Send To" command on a file on desktop Using Outlook 3
B Outlook 2010: Rule not working Using Outlook 4
V Outlook rule: to me but not through distribution list Using Outlook 1
F Missing rule in Outlook 2010 that was in Outlook 2003 Using Outlook 3
A Outlook Rule - How to set a rule which moves mails to a specific folder when you were BCC'ed? Using Outlook 2
S Microsoft Office Outlook 2010 Quick rule managent with a PST file as the default mail delivery locat Using Outlook 1
J A problem with a Rule in Outlook 2010 Using Outlook 8
G Outlook rule causing duplication Using Outlook 2
J Why isn't my Out of Office rule working in Outlook 2010? Using Outlook 2
Similar threads


















































Top