vba - Save emails daily incorporating if filename are duplicates -
i writing macro save emails daily. thought of situation can possibly occur. receive emails same subject sender, each email has different content. have set of statements handle this. maybe have copy, or maybe append time file name. code have right now.
public sub savemsgs(item outlook.mailitem) dim spath string dim dtdate date dim sname string dim enviro string dim ssender string dim strfolder string dim strnewfolder string dim save_to_folder string dim strmypath string dim intcount integer dim enviro = cstr(environ("userprofile")) sname = item.subject replacecharsforfilename sname, "_" ssender = item.sender dtdate = item.receivedtime sname = ssender & " - " & sname & ".msg" strnewfolder = format(date, "mm-dd-yyyy") strfolder = "c:\it documents\" & strnewfolder & "\" if len(dir(strfolder, vbdirectory)) = 0 mkdir (strfolder) end if save_to_folder = strfolder item.saveas save_to_folder & sname, olmsg end sub private sub replacecharsforfilename(sname string, _ schr 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 here code thinking bout adding.
do while true strmypath = strfolder & sname if objfso>fileexists(strmypath) intcount = intcount + 1 sname = copy (" & intcount & ") else exit end if loop would work trying do, or better append time filename?
to save date time seconds & subject
sname = format(dtdate, "mm-dd-yyyy", vbusesystemdayofweek, _ vbusesystem) & format(dtdate, "-hhnnss", _ vbusesystemdayofweek, vbusesystem) & "-" & sname & ".msg"
Comments
Post a Comment