Move sent items emails to hard disk

Status
Not open for further replies.

rollno

Member
Outlook version
Outlook 2010 64 bit
Email Account
IMAP
Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) 
 
Dim sName As String 
 
Dim sPath As String 
 
Dim enviro As String 
 
On Error Resume Next 
 
enviro = CStr(Environ("username")) 
 
Const olmsg = 3 
 
ReplaceCharsForFileName sName, "_" 
 
sPath = enviro & "C:\Users\username\Desktop\Sent emails\" 
 
sName = Item.Subject & ".msg" 
 
Debug.Print sPath & sName 
 
Item.SaveAs sPath & sName, olmsg 
 
End Sub 
 
Private Sub ReplaceCharsForFileName(fName As String, _
 sChr As String _ 
 
)
 sName = Replace(sName, "/", sChr)
 sName = Replace(sName, "\", sChr)
 sName = Replace(sName, ":", sChr)
 sName = Replace(sName, "?", sChr)
 sName = Replace(sName, Chr(34), sChr)
 sName = Replace(sName, "<", sChr)
 sName = Replace(sName, ">", sChr)
 sName = Replace(sName, "|", sChr)
 sName = Replace(sName, "#", sChr)
 sName = Replace(sName, ",", sChr)
 sName = Replace(sName, "||", sChr) 
 
End Sub
Please help this code works fine only if I do not have RE: in the subject line....I am not sure where I am making a mistake...this code could also be wrong or you may find some unnecessary lines in this...Please help...
 

Forum Admin

Senior Member
What is the error message if there is a re:?

I'm guessing the problem is the file name is not unique. To avoid problems, add the received time to the file name.

Dim dtDate As Date

Dim sName As String
dtDate = oMail.ReceivedTime
sName = Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
vbUseSystem) & Format(dtDate, "-hhnnss", _
vbUseSystemDayOfWeek, vbUseSystem) & "-" & sName & ".msg"

The date format is here: "yyyymmdd" and you can add hhmmss if you need to break it down - if you want to use separators, you can use any character that is valid for filenames, most people use - yyyy-mm-dd-hh-mm-ss but i prefer to use one solid number yymmddhhmmss

You could use the saved time instead (use Now instead of receivedtime) or use a random number - i have some macro samples at http://www.poremsky.com/office/sequential-numbers-random-character-keywords/
 

rollno

Member
Outlook version
Outlook 2010 64 bit
Email Account
IMAP
Actually I do nolt want to add the received time to the file name. Can you please help, I have another code as well but it does not work either...if there are no special characters in the subject line then it works fine .

------------------------------------Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Dim fName As String

Dim i

Const olmsg = 3

illegals = "#,/|\:" ' add any additional characters to the string

temp = Item.Subject

For i = 1 To Len(illegals)

temp = Replace(temp, Mid(illegals, i, 1), "_") ' replace illegal character with nothing

Next

fName = "C:\Users\unknown\Desktop\Sent emails\" & temp

Item.SaveAs fName, olmsg

End Sub
 

rollno

Member
Outlook version
Outlook 2010 64 bit
Email Account
IMAP
Wow my latest code is working now..we can close this thread...thank you all.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
if the problem is special characters, you need to clean the url.

Try this to clean the subject -

temp = Item.Subject
ReplaceCharsForFileName temp, "-"

Repeat each line for the characters that need to be removed -

Private Sub ReplaceCharsForFileName(temp As String, _
sChr As String)
temp = Replace(temp, "#", sChr)
temp = Replace(temp, Chr(34), sChr)

End Sub

http://www.slipstick.com/developer/code-samples/save-selected-message-file/ has a sample with a list of all of the characters.
 

rollno

Member
Outlook version
Outlook 2010 64 bit
Email Account
IMAP
if the problem is special characters, you need to clean the url.

Try this to clean the subject -

temp = Item.Subject
ReplaceCharsForFileName temp, "-"

Repeat each line for the characters that need to be removed -

Private Sub ReplaceCharsForFileName(temp As String, _
sChr As String)
temp = Replace(temp, "#", sChr)
temp = Replace(temp, Chr(34), sChr)

End Sub

http://www.slipstick.com/developer/code-samples/save-selected-message-file/ has a sample with a list of all of the characters.
Hi the lastest above code posted by me works...but it saves the email before it is sent...can it be modified so it can be copied after it is sent?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
No, the item send macro runs before its sent. If you want to send first, you need to use an itemadd macro to watch the sent folder and save it as it hits the sent folder.
 

rollno

Member
Outlook version
Outlook 2010 64 bit
Email Account
IMAP
No, the item send macro runs before its sent. If you want to send first, you need to use an itemadd macro to watch the sent folder and save it as it hits the sent folder.
Could you please add that code and send it to me, I am really not sure how the coding works...I am searching and doing it on my own..
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
See http://www.slipstick.com/outlook/archive-outlook/save-incoming-messages-hard-drive/ - it actually does what you want, except for incoming messages. Change it to olfoldersentitems and fix the filename as necessary.

- - - Updated - - -

See http://www.slipstick.com/outlook/archive-outlook/save-incoming-messages-hard-drive/ - it actually does what you want, except for incoming messages. Change it to olfoldersentitems and fix the filename as necessary.
 

rollno

Member
Outlook version
Outlook 2010 64 bit
Email Account
IMAP
got it thank u so much

- - - Updated - - -

got it thank u so much
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
S Send email via SMTP - use transport rules to add to senders inbox (then rule to move to sent items Exchange Server Administration 1
M Move Sent Items from server folder to personal folder Using Outlook 2
G Macro to move sent items from local folder to IMAP folder Using Outlook 4
P move mails after send to central mailbox-sent items folder Using Outlook 4
N Outlook - check sent items if messages sent from a specific account move it to another mailbox sent Using Outlook 3
O Rule to move (specific) messages from Sent folder to Specific folder Using Outlook 1
Mark White VBScript Move sent mail to non-default folder Outlook VBA and Custom Forms 5
Mark White VBScript Move sent mail to non-default folder Outlook VBA and Custom Forms 0
C Outlook 2013 - Email Gets Sent - But Does Not Move From Outbox to Sent Box Using Outlook 4
S how to keep "To" when move sent emails to other folder Using Outlook 1
N rule to move sent mail to the deleted folder in outlook Using Outlook 4
O Outlook 2010: Rule to move sent emails doesn't start if I Use "Send To" command on a file on desktop Using Outlook 3
J wireless always allows me to send/receive emails via outlook 2007. recent move to university gives me internet access but no emails can be sent or rec Using Outlook 1
B Create a rule to move emails after being sent to specific domains Outlook 2007 Using Outlook 1
B Move Sent Email to archival pst folder and mark as read - HOW TO Outlook VBA and Custom Forms 2
G Cannot Move Autocomplete File to New Computer Using Outlook 15
M Move to Folder Using Outlook 1
P Move emails between 2 mailboxes. Using Outlook 1
C Copy Move item won't work Outlook VBA and Custom Forms 2
N Macro to move all recipients to CC while replying Outlook VBA and Custom Forms 0
Commodore Move turns into "copy" Using Outlook 3
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
Jennifer Murphy Ctrl+Tab sometimes will not move through text a word at a time Using Outlook 1
V Outlook 2016 will not move emails in search results Using Outlook 4
M move to iCloud not working in outlook calendar Using Outlook 12
A Create date folder and move messages daily Outlook VBA and Custom Forms 1
Commodore Folders always closed in move/copy items dialog box Using Outlook 3
C Move Outlook 2007 to new PC with Outlook 365 Using Outlook 3
C Can't move folder, the folder is full Using Outlook 0
Nadine Rule to move attachments with specific name Outlook VBA and Custom Forms 1
A Move email items based on a list of email addresses Outlook VBA and Custom Forms 40
T Move calendar invites to new calendar Using Outlook 5
I Automating message move between folders Outlook VBA and Custom Forms 0
K Outlook Rules: Move a Copy Using Outlook 4
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
N Move emails of same conversation to same subfolder Using Outlook 6
P when i move inbox mails to another folder in outlook the mail disappears Using Outlook 1
Peter H Williams How to Move Mail item after processing Outlook VBA and Custom Forms 5
D Move Emails between Folders in Separate Mailbox Outlook VBA and Custom Forms 12
E Search for folder by key in subject then move new message to related folder Outlook VBA and Custom Forms 1
I Outlook 2013 Any way to move .OST file to new system? Using Outlook.com accounts in Outlook 5
O On click,I want to change subject line of selected mail and then reply to particular email and move Using Outlook 3
F "Move to" O365 feature to Outlook client via VBA Outlook VBA and Custom Forms 4
B Macro to manually move selected emails to network folder Outlook VBA and Custom Forms 1
L Making rule to move email to folder from one O365 domain Using Outlook 1
B Copy/Move Exchange inbox to Pop inbox Using Outlook 4
C Move from Outlook 2007 Enterprise (MOE) to Outlook Pro plus 2007 Using Outlook 1
Cdub27 Move Outlook 2016 Contacts to Other Folders - Extremely Slow !! Using Outlook 6
M code to move selected Outlook contacts to another folder Using Outlook 3
G Favorites panel entries move around after restarting Outlook 2016 Using Outlook 1
Similar threads


















































Top