Glen Orenstein
Member
- 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
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