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...
 
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/
 
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
 
Wow my latest code is working now..we can close this thread...thank you all.
 
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.
 
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?
 
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.
 
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..
 
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.
 
got it thank u so much

- - - Updated - - -

got it thank u so much
 
Status
Not open for further replies.
Similar threads
Thread starter Title 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
J Quick steps delete original email and move reply/sent email to folder Using Outlook 2
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
B Move Sent Email to archival pst folder and mark as read - HOW TO Outlook VBA and Custom Forms 2
H Move Selected emails to Local Drive Outlook VBA and Custom Forms 0
A Search folder and move the email Outlook VBA and Custom Forms 0
A Outlook 365 (OutLook For Mac)Move "On My Computer" Folder Items From Old To New Mac Computer Using Outlook 3
HarvMan Outlook 365 - Rule to Move an Incoming Message to Another Folder Using Outlook 4
humility36 Cannot move emails to archive - 440 error Outlook VBA and Custom Forms 1
B Outlook 2019 Automatically move email after assigning category Using Outlook 4
C Trying to move messages between imap accounts/folders Using Outlook 5
M Move command Outlook VBA and Custom Forms 11
C Code to move mail with certain attachment name? Does Not work Outlook VBA and Custom Forms 3
B Move emails from one account to another Outlook VBA and Custom Forms 2
N How to add or delete items to Move dropdown Menu Using Outlook 0
Commodore Unable to move message Using Outlook 3
N Line to move origEmail to subfolder within a reply macro Outlook VBA and Custom Forms 0
C Move or copy from field to field Outlook VBA and Custom Forms 0
T Outlook 365 Move newly created tasks automatically on save. Outlook VBA and Custom Forms 1
NVDon Create new Move To Folder list Outlook VBA and Custom Forms 0
P Print attachments automatically and move the mail to an existing folder called "Ted" Outlook VBA and Custom Forms 4
T Macro to move reply and original message to folder Outlook VBA and Custom Forms 6
F VBA to move email from Non Default folder to Sub folders as per details given in excel file Outlook VBA and Custom Forms 11
F Excel VBA to move mails for outlook 365 on secondary mail account Outlook VBA and Custom Forms 1
J Dopey move - deleted profile Using Outlook 1
GregS Outlook 2016 Move Outlook to new computer? Using Outlook 4
Witzker Macro to move @domain.xx of a Spammail to Blacklist in Outlook 2019 Outlook VBA and Custom Forms 7
G Move tasks up/down todo list by VBA Outlook VBA and Custom Forms 1
S Macro to move “Re:” & “FWD:” email recieved the shared inbox to a subfolder in outlook Outlook VBA and Custom Forms 0
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
D Move Email with Attachment to Folder Outlook VBA and Custom Forms 3
Eike Move mails via macro triggered by the click of a button? Outlook VBA and Custom Forms 0
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 0
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

Similar threads

Back
Top