move emails to windows folder and show sender details

Status
Not open for further replies.

Viet Nguyen

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Hi,

I have been asked to assist with finding a vb script to copy/move emails from inbox to a windows folder (ie C:\Saved Emails.

I can manually move the emails but the sender address or name doesn't appear in the Windows Folder.

I am hoping you can assist in creating a vb script which will move the emails to windows folder and also display sender names.

Thanking you in advance and hope to hear from you soon.

Regards,
Viet
 

Viet Nguyen

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Hi,

I have been asked to assist with finding a vb script to copy/move emails from inbox to a windows folder (ie C:\Saved Emails.

I can manually move the emails but the sender address or name doesn't appear in the Windows Folder.

I am hoping you can assist in creating a vb script which will move the emails to windows folder and also display sender names.

Thanking you in advance and hope to hear from you soon.

Regards,
Viet
UPDATE: This is a to be applied to a shared mailbox which I have access to.
 

Viet Nguyen

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Hi Michael,

Ive copied the script into Visual Basic and wanted to run it as a rule in Outlook but I could not see the script to select from the rules when creating the rule.

Is the script at www.vboffice.net/?smp=7, the whole script or just partial and I need to add to it?
Ive only made I amendment to the script. c:\mails\


Option Explicit

Public Enum olSaveAsTypeEnum
olSaveAsTxt = 0
olSaveAsRTF = 1
olSaveAsMsg = 3
End Enum

Private WithEvents Items As Outlook.Items

Private Const MAIL_PATH As String = "c:\mails\"

Private Sub Application_Startup()
Dim Ns As Outlook.NameSpace

Set Ns = Application.GetNamespace("MAPI")
Set Items = Ns.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
SaveMailAsFile Item, olSaveAsMsg, MAIL_PATH
End If
End Sub

Thanks
Viet

Private Sub SaveMailAsFile(oMail As Outlook.MailItem, _
eType As olSaveAsTypeEnum, _
sPath As String _
)
Dim dtDate As Date
Dim sName As String
Dim sFile As String
Dim sExt As String

Select Case eType
Case olSaveAsTxt: sExt = ".txt"
Case olSaveAsMsg: sExt = ".msg"
Case olSaveAsRTF: sExt = ".rtf"
Case Else: Exit Sub
End Select

sName = oMail.Subject
ReplaceCharsForFileName sName, "_"

dtDate = oMail.ReceivedTime
sName = Format(dtDate, "yyyymmdd", vbUseSystemDayOfWeek, _
vbUseSystem) & Format(dtDate, "-hhnnss", _
vbUseSystemDayOfWeek, vbUseSystem) & "-" & sName & sExt

oMail.SaveAs sPath & sName, eType
End Sub

Private Sub ReplaceCharsForFileName(sName 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)
End Sub
 

Viet Nguyen

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
I need to be able to manually pick the emails that come into the inbox rather then it auto move all emails.
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
A script that can be run by a rule must be declared this way
Code:
public sub whatever(item as mailitem)
...
end sub
 

Viet Nguyen

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
This script has worked for me.

Public Sub SaveMsg(Item As Outlook.MailItem)
Dim dtDate As Date
Dim sName As String
Dim sFile As String
Dim sExt As String
Dim sSubject As String

enviro = CStr(Environ("USERPROFILE"))

sSubject = Item.Subject
ReplaceCharsForFileName sSubject, "_"

sName = Item.SenderName
ReplaceCharsForFileName sName, "_"

dtDate = Item.ReceivedTime
sName = Format(dtDate, "ddmmyyyy", vbUseSystemDayOfWeek, _
vbUseSystem) & Format(dtDate, "-hhnnss", _
vbUseSystemDayOfWeek, vbUseSystem) & "-" & sSubject & "#####" & sName & ".msg"
' use My Documents in older Windows.
sPath = "c:\mails\"
Debug.Print sPath & sName
Item.SaveAs sPath & sName, olMSG
End Sub

Private Sub ReplaceCharsForFileName(sName 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)
End Sub
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
K VBA to move emails in folder to a windows folder Outlook VBA and Custom Forms 2
P Move emails between 2 mailboxes. Using Outlook 1
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
V Outlook 2016 will not move emails in search results Using Outlook 4
N Move emails of same conversation to same subfolder Using Outlook 6
D Move Emails between Folders in Separate Mailbox Outlook VBA and Custom Forms 12
B Macro to manually move selected emails to network folder Outlook VBA and Custom Forms 1
N Move red and unflagged emails to subfolder Outlook VBA and Custom Forms 1
I vba scrip to move emails based on long keywords list Outlook VBA and Custom Forms 0
G email returns after running macro to move emails Outlook VBA and Custom Forms 1
S How can I create a rule to move inbound emails from any of my contacts out of Inbox? Using Outlook 1
S Macro to print & move selected emails? Using Outlook 3
H Rule to move emails based on subject and content Outlook VBA and Custom Forms 1
H Move outlook emails >90 days to shared drive (Desktop) Folder Outlook VBA and Custom Forms 5
O Script to move emails to a folder based on various possible keywords Outlook VBA and Custom Forms 11
S how to keep "To" when move sent emails to other folder Using Outlook 1
N Outlook 2010 exchange - auto-move emails from @domain Exchange Server Administration 1
R Move sent items emails to hard disk Using Outlook 10
B OUTLOOK 2013: How Do I Move Emails to Folders stored on my Hard Drive? Using Outlook 3
S Outlook macro to move replied / forwarded emails to a seperate folder Using Outlook 1
C Help with a Macro to move emails to a different PST data file Using Outlook 4
A rule to move emails to a folder then want to delete them from that folder 2010 Using Outlook 5
T After updating Exchange 2010 from RTM to SP1, OWA clients cannot move or delete emails Using Outlook 4
T unable to move or delete emails in IMAP folder Using Outlook 2
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
A Outlook2010 - The emails stay in the Mailbox and doesn't move to the Personal folder Using Outlook 3
A emails eventually move themselves back from saved folder to inbox Using Outlook 4
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
R Move to folder rule for already downloaded emails Using Outlook 1
S Re: Unable to move emails from outlook to my documents Using Outlook 1
S How to move emails from Personal folders to Outlook inbox Using Outlook 6
B Create a rule to move emails after being sent to specific domains Outlook 2007 Using Outlook 1
G User can not move or delete emails Using Outlook 3
K Outlook 2010: not receiving emails after installing, and distribution lists did not move to Contacts Using Outlook 2
S BCC Emails to Email and Outlook Rule to move it folder Using Outlook 2
V Move old emails or emails with large attachments ? Outlook VBA and Custom Forms 1
J move contents from hundreds of emails into excel Outlook VBA and Custom Forms 4
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
Jennifer Murphy Ctrl+Tab sometimes will not move through text a word at a time Using Outlook 1
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
O Rule to move (specific) messages from Sent folder to Specific folder Using Outlook 1
Similar threads


















































Top