VBA in MS Outlook to save messages in a newly created folder

albertan

Member
Joined
Nov 9, 2017
Messages
30
Reaction score
0
Points
6
Location
Canada
Excel Version(s)
2013
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, _
vbUseSystem)

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
 
Back
Top