vba - Send two different mails when a cell reaches two different values (right) -
i'm developing program automatically send 2 different e-mail messages when cells in range reach 2 different values (1 or 2).
the code i'm using consists of:
a) private sub worksheet_calculate()
b) sub mail_with_outlook1()
sub code sub mail_with_outlook1 () sends 1 e-mail message text type content 1, 1 corresponding address registered in range of cells in column "af".
this happens when value of corresponding cell of range "ae10: ae45" equal “1” (see mylimit = 1).
i send second specific e-mail message text type content 2, 1 of corresponding addresses described in same range of column "af", when value of cell of same range "ae10: ae45" equal "2" (mylimit = 2).
private sub worksheet_calculate() dim formularange range dim notsentmsg string dim mymsg string dim sentmsg string dim mylimit double mylimit = 1 set formularange = me.range("ae10:ae104") on error goto endmacro: each formulacell in formularange.cells formulacell if isnumeric(.value) = false mymsg = "non numerico" else if .value = mylimit mymsg = sentmsg if .offset(0, 4).value = notsentmsg call mail_with_outlook1 end if else mymsg = notsentmsg end if end if application.enableevents = false .offset(0, 4).value = mymsg application.enableevents = true end next formulacell exitmacro: exit sub endmacro: application.enableevents = true msgbox "si รจ manifestato un errore." _ & vblf & err.number _ & vblf & err.description end sub
sub mail_with_outlook1() dim outapp object dim outmail object dim strto string, strcc string, strbcc string dim strsub string, strbody string set outapp = createobject("outlook.application") set outmail = outapp.createitem(0) strto = cells(formulacell.row, "af").value strcc = cells(formulacell.row, "ag").value strbcc = "" strsub = "my filename" strbody = "hello i0m frank .... eccc" outmail .to = strto .cc = strcc .bcc = strbcc .subject = strsub .body = strbody .importance = 2 .display end set outmail = nothing set outapp = nothing end sub
Comments
Post a Comment