View Full Version : VBA in MS Outlook to save messages in a newly created folder

2018-03-30, 11:18 PM
I'm trying to assign a VBA script in MS Outlook so that I can get all emails saved in a newly created folder (named by date, files also named by date).

I create a folder and assign name to it:

strNewFolderName = Format(dtDate , "yyyymmdd", vbUseSystemDayOfWeek, _

sName = Item.Subject
ReplaceCharsForFileName sName, "_"
MkDir ("C:\Users\Albertan\My Documents\Messages" & strNewFolderName)

Then I'm trying to save the email in this newly created folder:

sPath = "C:\Users\Albertan\My Documents\Messages"&StrNewFolderName
Debug.Print sPath & sName
Item.SaveAs sPath & sName, olMSG

But it is not saving there (it creates a folder though). If I remove variable name from path it saves it but one level up. I need to save it in the folder with same date format name as the email name format (also date format)

Something wrong with my SPath. I think it is not recognizing the folder name (variable that I use).

Does anybody have any suggestion?

Thank you