Welcome to the Excel Forum

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed.

Please Register to Remove these Ads

Please Register to Remove these Ads



Reply
  #1  
Old 03-24-2009, 06:36 PM
wotadude wotadude is offline
Forum Contributor
 
Join Date: 21 Aug 2008
Location: Hamilton, New Zealand
MS Office Version:2003 & 2007
Posts: 128
wotadude is becoming part of the community
macro to move messages from Sent Items from specific mailbox address

Please Register to Remove these Ads

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.
Reply With Quote
  #2  
Old 03-30-2009, 04:59 PM
wotadude wotadude is offline
Forum Contributor
 
Join Date: 21 Aug 2008
Location: Hamilton, New Zealand
MS Office Version:2003 & 2007
Posts: 128
wotadude is becoming part of the community
Re: macro to move messages from Sent Items from specific mailbox address

any solutions fellow forumists?
Reply With Quote
  #3  
Old 03-31-2009, 02:52 AM
ExlGuru's Avatar
ExlGuru ExlGuru is offline
Forum Administrator
 
Join Date: 17 Mar 2009
Location: India
MS Office Version:2003,2007
Posts: 222
ExlGuru is becoming part of the community
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
Reply With Quote
  #4  
Old 05-01-2009, 04:12 PM
bugmenot bugmenot is offline
Forum Contributor
 
Join Date: 28 Feb 2008
Location: USA
MS Office Version:2007
Posts: 135
bugmenot is becoming part of the community
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
Reply With Quote
  #5  
Old 05-01-2009, 04:20 PM
shg's Avatar
shg shg is offline
Forum Guru
 
Join Date: 20 Jun 2007
Location: The Great State of Texas
MS Office Version:2003, 2007
Posts: 18,549
shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay shg makes giving solutions look like childsplay
Re: macro to move messages from Sent Items from specific mailbox address

Please edit your post to add code tags.
__________________
Entia non sunt multiplicanda sine necessitate.
Reply With Quote


Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump