Save Mail Message to new folder created automatically

Status
Not open for further replies.

leuzzo

New Member
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
Hi ,
Please help me to do update in below code so as to create automatically a folder in established location (path D:\MailSave\FirstWordSubject), the folder name is with the first word from the subject mail. If it already exists (path D:\MailSave\) must just to copy in the message.

Sub SaveMsg(MyMail As MailItem)
On Error GoTo err

Dim strID As String
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim FolderName As String

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)

olMail.SaveAs "D:\MailSave\" & olMail.Subject & ".msg", olMSG

Set olMail = Nothing
Set olNS = Nothing
Exit Sub

err:
MsgBox err.Description, vbOKOnly + vbInformation, "Eroare"
End Sub
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Assuming the words are delimited by a space, and assuming the mailsave folder does already exit :
Code:
FolderName=Left(olMail.Subject, Instr(olMail.Subject, " ")-1)
FolderName="d:\mailsave\" & FolderName
mkDir FolderName
 
Status
Not open for further replies.
Top