Edit Subject (Multiple Accounts)

Status
Not open for further replies.

dan1_uk

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
On my work PC I have two outlook accounts, my account and a shared account.

All external emails that we receive have an annoying note added to the subject line which is basically a warning that it's an external email.

I used to have a script set up with a rule but for some reason the 'run a script' option is no longer available under rules. I'm guessing it was an update but I have no admin rights on the machine.

I've now found some VBA code online that I used to remove this unwanted note from all emails as they arrive.
But unfortunately this only works for my email address, not the shared account.

The code I am using is:

Option Explicit

Private WithEvents olInboxItems As Items

Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.Session
' instantiate objects declared WithEvents
Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub

Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
On Error Resume Next
Item.subject = Replace(Item.subject, "CAUTION: External email - ", "")
Item.Save
Set Item = Nothing
End Sub


Any Ideas on how to make this work for both accounts?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I used to have a script set up with a rule but for some reason the 'run a script' option is no longer available under rules. I'm guessing it was an update but I have no admin rights on the machine.
Yeah, a security update removed it, it can be restored using a reg key.
Run-a-Script Rules Missing in Outlook

if you cant use the reg edit (or convince the admin to), you can convert the script to 'itemadd - that watches the folder and run it on all new mail. It can watch any folder, but you need to tell it to watch the folder....

Duplicate these lines, changing the bolded part to a new object name.
Private WithEvents olInboxItems As Items
Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items

Copy the full macro, changing the object name
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)

To reference the other mailbox, Set sharedInboxItems = ***.Items, see
Working with VBA and non-default Outlook Folders
if its in as an account, you need to use the getfolderpath function or if its a in as a shared mailbox (notl isted in account settings), you need the shared code.

Because the macros are really short, duplicating you won't save code, but if it were longer, you could share the code:
Code:
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
RemoveWarning item
end sub

Private Sub sharedInboxItems_ItemAdd(ByVal Item As Object)
RemoveWarning item
end sub

Private Sub RemoveWarning(ByVal Item As Object)
On Error Resume Next
Item.subject = Replace(Item.subject, "CAUTION: External email - ", "")
Item.Save
Set Item = Nothing
End Sub
 

dan1_uk

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Yeah, a security update removed it, it can be restored using a reg key.
Run-a-Script Rules Missing in Outlook

if you cant use the reg edit (or convince the admin to), you can convert the script to 'itemadd - that watches the folder and run it on all new mail. It can watch any folder, but you need to tell it to watch the folder....

Duplicate these lines, changing the bolded part to a new object name.
Private WithEvents olInboxItems As Items
Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items

Copy the full macro, changing the object name
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)

To reference the other mailbox, Set sharedInboxItems = ***.Items, see
Working with VBA and non-default Outlook Folders
if its in as an account, you need to use the getfolderpath function or if its a in as a shared mailbox (notl isted in account settings), you need the shared code.

Because the macros are really short, duplicating you won't save code, but if it were longer, you could share the code:
Code:
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
RemoveWarning item
end sub

Private Sub sharedInboxItems_ItemAdd(ByVal Item As Object)
RemoveWarning item
end sub

Private Sub RemoveWarning(ByVal Item As Object)
On Error Resume Next
Item.subject = Replace(Item.subject, "CAUTION: External email - ", "")
Item.Save
Set Item = Nothing
End Sub
Yeah, a security update removed it, it can be restored using a reg key.
Run-a-Script Rules Missing in Outlook

if you cant use the reg edit (or convince the admin to), you can convert the script to 'itemadd - that watches the folder and run it on all new mail. It can watch any folder, but you need to tell it to watch the folder....

Duplicate these lines, changing the bolded part to a new object name.
Private WithEvents olInboxItems As Items
Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items

Copy the full macro, changing the object name
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)

To reference the other mailbox, Set sharedInboxItems = ***.Items, see
Working with VBA and non-default Outlook Folders
if its in as an account, you need to use the getfolderpath function or if its a in as a shared mailbox (notl isted in account settings), you need the shared code.

Because the macros are really short, duplicating you won't save code, but if it were longer, you could share the code:
Code:
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
RemoveWarning item
end sub

Private Sub sharedInboxItems_ItemAdd(ByVal Item As Object)
RemoveWarning item
end sub

Private Sub RemoveWarning(ByVal Item As Object)
On Error Resume Next
Item.subject = Replace(Item.subject, "CAUTION: External email - ", "")
Item.Save
Set Item = Nothing
End Sub

Thanks for this, I’ll take a look at it when I’m back at work on Monday.

Cheers!
 

dan1_uk

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
I have now updated the code and can confirm it's working, thanks very much.
However I do have another issue.

I have a rule set up in Outlook to copy some emails from the shared account into a sub-folder in my account.
The rule is working but it copies the email before it has removed the unwanted text from the subject.

So the copied versions in my sub-folder still include the unwanted text.

Please see my code below:

Code:
Option Explicit

Private WithEvents olInboxItems As Items
Private WithEvents sharedInboxItems As Items

Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.Session

Dim NS As Outlook.NameSpace
Dim objOwner As Outlook.Recipient

Set NS = Application.GetNamespace("MAPI")
Set objOwner = NS.CreateRecipient("xxxxxx@xxxxxx.com")
objOwner.Resolve

' instantiate objects declared WithEvents
Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set sharedInboxItems = NS.GetSharedDefaultFolder(objOwner, olFolderInbox).Items
End Sub




Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
RemoveWarning Item
End Sub

Private Sub sharedInboxItems_ItemAdd(ByVal Item As Object)
RemoveWarning Item
End Sub

Private Sub RemoveWarning(ByVal Item As Object)
On Error Resume Next
Item.subject = Replace(Item.subject, "CAUTION: External email - ", "")
Item.Save
Set Item = Nothing
End Sub
Thanks
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Just one extra folder? You can watch that folder too.
Set olmysubfolderitems = objNS.GetDefaultFolder(olFolderInbox).folders("subbfolder").Items
(and all the other lines for olinboxitems)
However, if you have too many folders to watch, its unwieldy to watch each one.

Tip: if the folder is a subfolder of Inbox, use
dim olInbox as outlook.folder ' this may need to be up with the withevents lines

Set olInbox = objNS.GetDefaultFolder(olFolderInbox)
Set olInboxItems = olInbox.Items
Set olsubfolderItems = olInbox.Folders("subfolder").Items
 

dan1_uk

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Thanks again, this has worked a treat!
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
A Edit subject - and change conversationTopic - using VBA and redemption Outlook VBA and Custom Forms 2
R Edit Subject Line of Meeting Invitation? Using Outlook 1
P Edit Subject for every sent message Outlook VBA and Custom Forms 3
J Edit auto-complete list in Outlook 2016+/365? Using Outlook 0
J Message search and edit, another way? Outlook VBA and Custom Forms 4
L Wierd Office 365 Contact unable to edit body of random contacts Using Outlook 5
N VBA Script to Open highlighted e-mail and Edit Message Outlook VBA and Custom Forms 5
S Unable to Edit Contact Information in Certain Contact Folders Using Outlook 3
S Outlook.com cannot edit some contacts Using Outlook.com accounts in Outlook 5
B My outlook calendar edit issue Outlook VBA and Custom Forms 0
D VBA to edit body of incoming email and forwarding it Outlook VBA and Custom Forms 11
Diane Poremsky Edit and Save Outlook's Read-Only Attachments New Slipstick.com Articles 0
P "Edit Message" feature removed in Outlook 2016 for Mac Outlook VBA and Custom Forms 0
snissen Where is "Edit Message" in Outlook 2016? Using Outlook 2
P People/Contact Record gets deleted when I edit it? Using Outlook 3
C Edit/Create Pen Not Working Outlook 2013 Using Outlook 1
X Bulk edit Contact forms Using Outlook 2
A Contact address disappears when opened to edit Using Outlook 5
J Can invitee edit details? Using Outlook 1
G Outlook 2013: Cannot Edit default Holiday Calendar Using Outlook 2
V Custom form won't open for edit Outlook VBA and Custom Forms 3
M Bulk Edit contact notes BCM (Business Contact Manager) 1
M Any way to edit the message field on a 2010 Outlook Form? Using Outlook 3
S OL 2010 shortcut to edit received mail Using Outlook 3
A Cannot edit or open existing contact nor add new ones. BCM (Business Contact Manager) 1
T Exchange 2010: 'could not save item' and 'Unknown error' when edit calendars Exchange Server Administration 1
M Outlook 2003: Cannot edit default Contact Form Using Outlook 11
S how can i edit email address/es from the from field Using Outlook 5
M How to edit a monthly calendar to remove the cover page Calendar Printing Assistant 1
S How do I edit an attachment in an invite without notifying the attendees? Using Outlook 2
B Notice to user of appt. set by person with permission to edit (Outlook 2003) Using Outlook 7
H Edit email message Using Outlook 7
F Text Format Change - Bulk Edit Contact Notes Using Outlook 2
J Edit/Delete Meetings using Android Phone Using Outlook 4
M How to edit the "Home"tab with custom toolbar Using Outlook 4
S Assistants can't edit boss' calendar Using Outlook 3
D Outlook 2007 - how to edit calendar details style to include day Using Outlook 1
S Edit Contacts form in Outlook 2007 (without Business Contacts Manager) Using Outlook 2
Y Edit multiple rules in Outlook 2010 Using Outlook 1
R Critical problem - cannot edit my own meeting Using Outlook 3
A Using Word 2010 to edit Outlook message Using Outlook 2
C How to allow admins to enable ActiveSync and edit address book information in EMC Exchange Server Administration 3
P Add or edit stationary in Outlook 2010 Using Outlook 2
S How to edit the resource notification emails which Exchange sends? Exchange Server Administration 4
L SIGNATURE Advanced Edit Editor Using Outlook 5
S Need to turn off the insertion of a space before and after each edit in a reply Using Outlook 1
T user unable to edit calendar entries created on a calendar they are a delegate on Using Outlook 1
D Unable to edit attendee list in meeting Using Outlook 4
L not able to access signatures to modify, add, or edit. Using Outlook 1
S Re: Cannot access signatures in Outlook 2007. Cannot edit existing one or and a new one. Using Outlook 1
Similar threads


















































Top