Link to home
Start Free TrialLog in
Avatar of maherusa
maherusaFlag for United States of America

asked on

Outlook 2007 Macro: Move Exchange messages On Exit

Hello,

Please help me modify the code below to accept messages within my Exchange 2003 environment itself (i.e. from an Exchange email account to my Exchange email account). The current scenario accepts external SMTP messages only.

Thank you
Sub CRBQuit()
Const The_MailAccount_Name = "fred@fred.com"
Dim obj As Object
Dim mai As mailitem
Dim destFolder As Outlook.Folder
 
    Set destFolder = Application.Session.GetDefaultFolder(olFolderInbox).folders("experts Exchange")
    For Each obj In Application.Session.GetDefaultFolder(olFolderInbox).items
        If obj.Class = olMail Then
            Set mai = obj
            If mai.SenderEmailAddress = The_MailAccount_Name Then
                mai.Move destFolder
            End If
        End If
    Next
End Sub

Open in new window

Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

It is a matter of either:

Changing the mail address format to that of your server or adding an additional function to derive the SMTP address.

First option:

Try selecting an email from an internal address in the explorer, (don't open it though) then in teh VBE type in the immediate window, (ctrl + G to display it):

?application.activeexplorer.selection(1).senderemailaddress. and armed with this information we can edit the process to cater for both internal and external  addresses.

Chris
Avatar of maherusa

ASKER

Thanks Chris for the reply, but Ctrl+G didn't result in anything... I may also have not used the command correctly. Can you please give me more instructions on how to get the address using this shortcut?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial