VBA Code to change subject Like

Status
Not open for further replies.

Freeda

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
We get an email that contains a subject line like "Quiz Results 1234-FY14-POR- 0 (0%)" (or something else in the middle). I would like to change the "Quiz Results" to "POR #" and then remove the "-0(0%)" from the end altogether. I would like to do this with a code, but so far nothing is working. I can get it to change the whole subject line, but can't get it to replace the portion and then remove the last portion.

Any help would be greatly appreciated.

Also, how can I get the script to run even when the person doesn't have their Outlook open? I would like the script to run and then forward, but the person is not always there to have Outlook open. When I add the Run Script to the rule it forces it to be a client-only rule and that will not work.
 
Removing the first part is easy - mid(subject, 14, len(subject)-14) - that says get the middle of the string, beginning at character #14. you could also use right(subject,len(subject)-14).

If the value at the end is always the same, you'd subtract 17 from the length.

Assuming the value at the end varies, you'll look for something unique, like POR and subtract it from the length. If you are keeping POR, add 3 instead of subtracting 1.

Then put what's left together with POR leading: subject = "POR #" & subject

Code:
Sub TrimSubject()
Dim olMsg As MailItem
Set olMsg = Application.ActiveExplorer.Selection.Item(1)
olMsg.subject = Mid(olMsg.subject, 14, Len(olMsg.subject) - InStr(1, olMsg.subject, "POR") - 1)
Debug.Print olMsg.subject
olMsg.subject = "POR #" & olMsg.subject
Debug.Print olMsg.subject
End Sub
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
B Requesting VBA code to make Outlook prompt for confirmation when deleting a task? Outlook VBA and Custom Forms 4
N VBA Code Not Working correctly Outlook VBA and Custom Forms 1
D Outlook 2021 Using vba code to delete all my spamfolders not only the default one. Outlook VBA and Custom Forms 0
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
D VBA code to select a signature from the signatures list Outlook VBA and Custom Forms 3
S Excel vba code to manage outlook web app Using Outlook 10
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
S Add VBA save code Using Outlook 0
C Auto Run VBA Code on new email Outlook VBA and Custom Forms 1
F VBA code to dock Styles whenever I write or edit an email Outlook VBA and Custom Forms 0
S Skype for business meeting vba code Outlook VBA and Custom Forms 1
R Expand VBA Permanent Delete Code Outlook VBA and Custom Forms 6
B Outlook Business Contact Manager with SQL to Excel, User Defined Fields in BCM don't sync in SQL. Can I use VBA code to copy 1 field to another? BCM (Business Contact Manager) 0
A VBA Code in Outlook disappears after first use Outlook VBA and Custom Forms 1
F VBA to ensure a code is entered in Subject title Outlook VBA and Custom Forms 1
N Open & Save VBAProject.Otm using VBA Code Outlook VBA and Custom Forms 1
R VBA Code to permanently delete selected email Outlook VBA and Custom Forms 10
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1
S VBA Code to move mail items from search folder to inbox subfolder Outlook VBA and Custom Forms 4
B VBA Code to create appointment from email Outlook VBA and Custom Forms 1
D VBA Code to strip Subject Line when replying or forwarding Using Outlook 3
M VBA Code to Restart Outlook on error Outlook VBA and Custom Forms 3
Z Default VBA code for extracting data from email (Outlook) to Excel? Outlook VBA and Custom Forms 1
T VBA to Sort Rules [A-Z] - code provided Outlook VBA and Custom Forms 9
M VBA Auto-Reply code for Two Mailboxes on one Outlook Session. Outlook VBA and Custom Forms 4
Z Protecting VBA code - anything new? Outlook VBA and Custom Forms 2
G VBA code to enable a rule based on time of day for a IMAP mail account Outlook VBA and Custom Forms 14
S VBA code to rename a task (flagged message) Outlook VBA and Custom Forms 1
M VBA code to save email attachments (PDF) as email subject line Outlook VBA and Custom Forms 1
Diane Poremsky Pasting VBA code (and other editing) Outlook VBA and Custom Forms 4
C Required VBA code to complete task when replied to Outlook VBA and Custom Forms 2
Kelli VBA code for Outlook Using Outlook 1
S Requried a VBA Code to export Calander details to excel... Outlook VBA and Custom Forms 4
M VBA Code to extract data from an Outlook Form Using Outlook 0
M VBA code needed to move from Outlook 2010 subfolder to Symantec Vault subfolde Using Outlook 0
C In need of VBA code to read / parse HTML - Outlook emails Using Outlook 0
R [VBA] complicated(?) outlook events - need help with code Using Outlook 15
R how to get Outlook VBA code to work on the current folder Using Outlook 3
J VBA code can't be completely executed in outlook 2013 Using Outlook 0
D VBA: Send-From Code for Template Shortcut? Using Outlook 0
P VBA Code being completely ignored by Outlook Using Outlook 7
M Updating VBA code from outlook 2007 to outlook 2010 Using Outlook 1
J VBA code to determine 'show' state of SearchBar Using Outlook 7
D VBA code running on Server? Shared mailbox email routing Using Outlook 3
L Send E-mail with VBA code from [E-mail Distribution Group] if I have “Send as” Using Outlook 6
S Outllok 2007 VBA code to send mail automatically from drafts folder Using Outlook 1
S ThisOutlookSession in VBA not there anymore and code is gone Using Outlook 2
F No Attachment Warning - VBA Code HELP Outlook VBA and Custom Forms 1
J VBA code (rules) won't work after reboot Outlook VBA and Custom Forms 2
N VBA code to show today's date + a sequencial number in subject lin Outlook VBA and Custom Forms 1

Similar threads

Back
Top