email returns after running macro to move emails

Status
Not open for further replies.
Outlook version
Outlook 2013 64 bit
Email Account
Office 365 Exchange
I have a macro that I have modified that moves emails to a sub folder based on the emails address domain.

The problem is after they are moved they show up again. My environment is desktop: outlook 2013. Email is outlook online / office 365. I have multiple accounts within the outlook 2013 but the email is being moved within the same pst as it received.

the macro is listed below. Your help is greatly appreciated.

Public Sub M2El2FldrsbblbPl_script(oMsg As MailItem)
On Error Resume Next

Dim sDomain As String 'The Sender's domain
Dim oNS As Outlook.NameSpace 'My namespace
Dim oInbox As Outlook.MAPIFolder 'My Inbox
Dim oTarget As Outlook.MAPIFolder 'The domain folder
'Dim Sub1 As Outlook.MAPIFolder 'The Sub1
'Dim Sub2 As Outlook.MAPIFolder 'The Sub2
' Dim Sub3 As Outlook.MAPIFolder 'The Sub3

'If it's not your domain, decipher the domain.
If InStr(oMsg.SenderEmailAddress, "/O=") < 1 Then
sDomain = Mid(oMsg.SenderEmailAddress, InStr(oMsg.SenderEmailAddress, "@") + 1)
Else
sDomain = "xyz.com"
End If

'Get the inbox.
Set oNS = Application.GetNamespace("MAPI")
Set oInbox = oNS.GetDefaultFolder(olFolderInbox)
'Set oSub1 = oInbox.Folders("1-Professional_BBLB")
'Set oSub2 = oSub1.Folders("@Reference")
'Set oSub3 = oSub2.Folders("@Reference")

'Set the domain folder if it exists.
'Set oTarget = oSub2.Folders(sDomain)
Set oTarget = oInbox.Folders("1-Personal_xyz").Folders("@Reference").Folders(sDomain)

'In case the folder doesn't exist...
If oTarget Is Nothing Then
oInbox.Folders("1-Personal_xyz").Folders("@Reference").Folders.Add (sDomain)
Set oTarget = oInbox.Folders("1-Personal_xyz").Folders("@Reference").Folders(sDomain)
End If

'Move the new mail to the folder.
oMsg.Move oTarget

'Cleanup.
'Set oSub3 = Nothing
'Set oSub2 = Nothing
'Set oSub1 = Nothing
Set oTarget = Nothing
Set oInbox = Nothing
Set oNS = Nothing
End Sub



Thanks,
glen
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
D Outlook 2016 IMAP Connection Returns All Email but outlook.com does NOT Using Outlook.com accounts in Outlook 2
S Outlook email to configure setup for each mail Outlook VBA and Custom Forms 0
S Macro to extract email addresses of recipients in current drafted email and put into clipboard Outlook VBA and Custom Forms 1
A Is there an ID field you can use to pair a reply to the sent email? Outlook VBA and Custom Forms 4
C Auto Run VBA Code on new email Outlook VBA and Custom Forms 1
M How create a Rule to filter sender's email with more that one @ sign Using Outlook 1
A Prepending Email Addrs with "Display Name <email>" Has Stopped Working Using Outlook 0
Bering Forward selected email without the original email appended Outlook VBA and Custom Forms 0
Aussie Rules Run a Script on an Incoming Email OK and then the Email reverts Outlook VBA and Custom Forms 0
W Reply to email Using Outlook 4
F Junk Email does not get added to the Blocked Sender List Using Outlook 4
B disappearing original when attach to email Using Outlook 1
W September 2020 - No Default Email Client message after Office Update Using Outlook 1
glnz O365 - How to combine the Inboxes for four email accounts into a single Inbox Using Outlook 7
glnz O365 - How to send from acct 2 but showing email name from acct 1 as From - alias? Using Outlook 1
S Macro to move “Re:” & “FWD:” email recieved the shared inbox to a subfolder in outlook Outlook VBA and Custom Forms 0
D Move Email with Attachment to Folder Outlook VBA and Custom Forms 3
E Asking user to select multiple options in a list in an email Outlook VBA and Custom Forms 0
K Use VBA to find Sender and Recipient from Microsfot 365 Journaled Email Items Outlook VBA and Custom Forms 3
B Add ComboBox Value to Body of Email Outlook VBA and Custom Forms 1
A Backup Email Accounts On OutLook For Mac 2016 (Microsoft 365 subscription version) Using Outlook 0
F VBA code to dock Styles whenever I write or edit an email Outlook VBA and Custom Forms 0
G Inbox shows old email Using Outlook 3
L Email with correct To address but displaying name of a related person Using Outlook 0
A Two Inboxes, Same Email? Using Outlook 3
B Adding signature to bottom of VBA reply email Outlook VBA and Custom Forms 1
J To delete the draft email Using Outlook 2
B VBScript doesn't run on Recipient Email Outlook VBA and Custom Forms 2
J Autoreply email recieved from specific sender after deleting some text from body. Using Outlook 0
M Outlook 2013 reminder email by using Outlook vba Outlook VBA and Custom Forms 2
D Sending email from Office 365 alias in Outlook Using Outlook 3
S Macro or plug-in to see if specific person was included in this email Outlook VBA and Custom Forms 4
S Body text of Email from invite date/time Outlook VBA and Custom Forms 7
R Outlook 2010 How do you export 2 email Accounts' 2010 Inbox Files to new computer (2019)? Using Outlook 0
R Auto display of new email does not work on non-default account Outlook VBA and Custom Forms 0
J Automatically forward email and apply template Outlook VBA and Custom Forms 0
L Outlook saved email templates Using Outlook 1
B VBA to convert email to task, insert text of email in task notes, and attach copy of original email Outlook VBA and Custom Forms 4
T How can you include Junk Email in Search Results like you can include Deleted Items? Using Outlook 3
B Extracting email addresses from a folder - how to also get the name of the person the address is for? Using Outlook 5
W Replyin to the reply-to email address Outlook VBA and Custom Forms 0
E How to display "Change Folder" in Change Default Email Delivery Location in Exchange Outlook 2016 Using Outlook 1
M Extract all links from Outlook email, send to Excel Using Outlook 2
O Forward a email with modified body Automatically. Outlook VBA and Custom Forms 0
B Outlook 2003 email sending & receiving suddenly stopped working Using Outlook 3
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
O Email not leaving Outbox when using Excel VBA to sync Outlook account Outlook VBA and Custom Forms 4
T The non-email functions Using Outlook 8
P Outlook 2013 Word Share doc as Email Attachment now brings up Eudora. Using Outlook 1
C How to rename subject line and forward the email Outlook VBA and Custom Forms 2

Similar threads

Top