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
 
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.
 
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
 
upload_2015-2-26_11-23-15.png
 

Attachments

  • upload_2015-2-26_11-22-53.png
    upload_2015-2-26_11-22-53.png
    45.5 KB · Views: 590
I need to be able to manually pick the emails that come into the inbox rather then it auto move all emails.
 
A script that can be run by a rule must be declared this way
Code:
public sub whatever(item as mailitem)
...
end sub
 
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.
Similar threads
Thread starter Title Forum Replies Date
K VBA to move emails in folder to a windows folder Outlook VBA and Custom Forms 2
H Move Selected emails to Local Drive Outlook VBA and Custom Forms 0
humility36 Cannot move emails to archive - 440 error Outlook VBA and Custom Forms 1
B Move emails from one account to another Outlook VBA and Custom Forms 2
P Move emails between 2 mailboxes. Using Outlook 0
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
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
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
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
J Quick steps delete original email and move reply/sent email to folder Using Outlook 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

Similar threads

Back
Top