Outlook 2010 VBA Save Message as MSG Will Not Work as Script -


i trying script inside outlook rule automatically save e-mail messages file server when received user/domain.

i found following vba script on site , works if manually run it, not work inside outlook rule says use script.

sub savemessageasmsg()   dim omail outlook.mailitem   dim objitem object   dim spath string   dim dtdate date   dim sname string   dim enviro string      enviro = cstr(environ("userprofile"))    each objitem in activeexplorer.selection    if objitem.messageclass = "ipm.note"     set omail = objitem    sname = omail.subject   replacecharsforfilename sname, "-"    dtdate = omail.receivedtime   sname = sname & ".msg"      spath = enviro & "\desktop\allied e-file\"   debug.print spath & sname   omail.saveas spath & sname, olmsg    end if   next  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, ":", 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 

but not work inside outlook rule says use script

the argument must type mailitem subroutine available in rules wizard in outlook work

example

public sub savemessageasmsg(omail outlook.mailitem)       'your code here  end sub 

edit

tested on outlook 2010

option explicit sub savemessageasmsg(item outlook.mailitem)     dim objitem object     dim spath string     dim dtdate date     dim sname string     dim enviro string      enviro = cstr(environ("userprofile"))      sname = item.subject     replacecharsforfilename sname, "-"      dtdate = item.receivedtime     sname = sname & ".msg"      spath = enviro & "\desktop\allied e-file\"         debug.print spath & sname     item.saveas spath & 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, ":", 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 

see here how create rule


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -