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
N Save Selected Email Message as .msg File Outlook VBA and Custom Forms 0
HarvMan Toggle between calendar and email in Outlook 365 Using Outlook 2
F Email being marked as Spam by Gmail and not being visible in Outlook Using Outlook 3
G Email time stamp Using Outlook 2
G Schedule recurring email and attachments display Outlook VBA and Custom Forms 3
G Save and Rename Outlook Email Attachments Outlook VBA and Custom Forms 0
B Need to Copy an email to a subfolder Outlook VBA and Custom Forms 2
M How to setup outlook after importing old account information - Entering email account info creates with "(1)" after the account! Using Outlook 1
K Multiple Rules on Single Email Using Outlook 2
F VBA to move email from Non Default folder to Sub folders as per details given in excel file Outlook VBA and Custom Forms 8
e_a_g_l_e_p_i Outlook 2010 How to set default email address for website links Using Outlook 3
O Same email address, same person, names in so many ways Using Outlook 4
D Create new email from the received Email Body with attachment Outlook VBA and Custom Forms 10
D Outlook launch email showing new unread email in reading pane Using Outlook 11
B Zoom automatically next email item (VBA) Outlook VBA and Custom Forms 2
K Outlook adds space to rows in HTML email signatures viewed on mobile Using Outlook 1
M HTML email signature in Outlook Using Outlook 1
M Respond to Outlook Email Outlook VBA and Custom Forms 0
U Outlook locking up when replying to Email Using Outlook 7
S Email Generated from another program and then edited sends original email. Using Outlook 2
G Forward email body to other mail list directly from Exchange server Exchange Server Administration 1
S Unable to extract text from an Outlook email message Using Outlook 2
T Original email text not shown when replying or forwarding the email. Using Outlook 6
H Search Email Header for Content Type Outlook VBA and Custom Forms 1
A VBA Script - Print Date between first email in Category X and last email in Category Y Outlook VBA and Custom Forms 3
R Problem moving file “Email folders.pst” to new PC Using Outlook 5
P Sending email from outlook IMAP to GMAIL where embedded images are added as attachment Using Outlook 1
D auto forward base on email address in body email Outlook VBA and Custom Forms 0
P How did hacker cause link to delete and archive containing email? Using Outlook 6
I 'quote marks' around email name Using Outlook 1
N contact list seen in Contact folder but knot in Address book or when 'TO' button is clicked in new email Using Outlook 0
T Junk Email does not get added to the Blocked Sender List Using Outlook 0
P i-Phone 6s Plus receiving 2 notifications from Outlook email Using Outlook 1
C WARNING - DO NOT USE AN OUTLOOK.COM ADDRESS FOR GOOGLE ACCOUNT RECOVERY EMAIL Using Outlook 10
T Why is every new email pinned (to keep it on top)? Windows 10 Using Outlook 6
M Outlook, send to > mail recipient - results in plain text email Using Outlook 1
P Can I create a Rule that sends me an email when I get a Task? Using Outlook 3
M Issue transferring Outlook 2016 email accounts & settings onto new computer Using Outlook 8
R Auto Assign Category colours to Incoming Emails based on whom the email is addressed Outlook VBA and Custom Forms 3
S Outlook email to configure setup for each mail Outlook VBA and Custom Forms 1
S Macro to extract email addresses of recipients in current drafted email and put into clipboard Outlook VBA and Custom Forms 2
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

Similar threads

Top