+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Valued Forum Contributor
    Join Date
    08-22-2008
    Location
    Hamilton, New Zealand
    MS-Off Ver
    Office 2007
    Posts
    207

    macro to move messages from Sent Items from specific mailbox address

    In outlook i manage multiple mailboxes.
    And when sending a message i select from which email address i am sending it from (on behalf of).

    I need a macro to move all sent items from my personal mailbox for a specific "From" address to the specific mailbox sent items.
    As mail items sent on behalf are filed in the personal sent items, not that of the behalf of mailbox.

    i would like to run this on demand (via toolbar button) and an option to run on outlook close and/or outlook open/start-up.

  2. #2
    Valued Forum Contributor
    Join Date
    08-22-2008
    Location
    Hamilton, New Zealand
    MS-Off Ver
    Office 2007
    Posts
    207

    Re: macro to move messages from Sent Items from specific mailbox address

    any solutions fellow forumists?

  3. #3
    Forum Administrator
    Join Date
    03-18-2009
    Location
    India
    MS-Off Ver
    2003,2007
    Posts
    222

    Re: macro to move messages from Sent Items from specific mailbox address

    Try this code may be helpful for you:

    Code:
    Sub CopySentItemsMessagesToPSTFile(PSTFilePath As String)
    On Error Resume Next
    
    Dim objNS As Outlook.NameSpace
    Dim objSentItemsFolder As Outlook.MAPIFolder, objDestinationFolder As
    Outlook.MAPIFolder
    Dim objItem As Object
    Dim intX As Integer
    
    Set objNS = Application.GetNamespace("MAPI")
    Set objSentItemsFolder = objNS.GetDefaultFolder(olFolderSentMail)
    
    objNS.AddStore PSTFilePath 'PST will be created if it doesn't exist
    Set objDestinationFolder = objNS.Folders.GetLast 'Get the PST we just
    added
    Set objDestinationFolder = objDestinationFolder.Folders("Inbox")
    If Err.Number <> 0 Then
    'Inbox doesn't exist; create it
    Set objDestinationFolder = objDestinationFolder.Folders.Add("Inbox",
    olFolderInbox)
    End If
    
    For intX = objSentItemsFolder.Items.Count To 1 Step -1
    Set objItem = objSentItemsFolder.Items(intX)
    objItem.Move objDestinationFolder
    Next
    
    Leave:
    Set objNS = Nothing
    Set objSentItemsFolder = Nothing
    Set objDestinationFolder = Nothing
    Set objItem = Nothing
    End Sub
    ExlGuru

  4. #4
    Banned User!
    Join Date
    02-28-2008
    Location
    USA
    MS-Off Ver
    2007
    Posts
    136

    Re: macro to move messages from Sent Items from specific mailbox address

    Private WithEvents sentItems As Items

    Private Sub Application_Startup()
    Dim objNS As NameSpace
    Dim objRecipient As Recipient
    Dim objFolder As MAPIFolder

    Set objNS = Me.GetNamespace("MAPI")
    Set objRecipient = objNS.CreateRecipient(objNS.CurrentUser.Address)
    objRecipient.Resolve

    If objRecipient.Resolved Then
    Set objFolder = objNS.GetDefaultFolder(olFolderSentMail)
    Set sentItems = objFolder.Items
    Set objFolder = Nothing
    Else
    MsgBox ("Error: Name Not Resolved - Please Contact Jon P")
    End If
    Set objRecipient = Nothing
    Set objNS = Nothing
    End Sub

    Private Sub sentItems_ItemAdd(ByVal Item As Object)
    Dim objItem As Outlook.MailItem
    Dim objNS As NameSpace
    Const g_PR_SMTP_ADDRESS_W = &H39FE001F

    If (TypeOf Item Is Outlook.MailItem) Then
    Set objItem = Item
    Set objSession = CreateObject("MAPI.Session")
    objSession.Logon "", "", False, False
    strEntryID = objItem.EntryID
    strStoreID = objItem.Parent.StoreID
    Set objMessage = objSession.GetMessage(strEntryID, strStoreID)
    strAddress = objMessage.Sender.Address

    If Not InStr(strAddress, "@") Then
    On Error Resume Next
    strAddress = objMessage.Sender.Fields(g_PR_SMTP_ADDRESS_W).Value
    End If
    objSession.Logoff
    Set objMessage = Nothing
    Set objSession = Nothing

    Select Case True
    Case InStr(LCase(strAddress), "jon.p@xxx.com")
    strMailBox = "Mailbox - Jon P"
    Case Else
    strMailBox = ""
    End Select
    Set objNS = Application.GetNamespace("MAPI")
    Set CDS_SentItems = objNS.Folders(strMailBox).Folders("Sent Items")
    objItem.Move CDS_SentItems
    Set CDS_SentItems = Nothing
    Set objNS = Nothing
    Set objItem = Nothing
    End If
    End Sub

  5. #5
    Forum Moderator shg's Avatar
    Join Date
    06-21-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007
    Posts
    25,129

    Re: macro to move messages from Sent Items from specific mailbox address

    Please edit your post to add code tags.
    Microsoft MVP - Excel
    Entia non sunt multiplicanda sine necessitate

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0