vba - Outlook mail with excel: Issue with body text and variable -


i'm having trouble getting .body text work.

i can create item in outlook. "to:" , "subject" correct, body text not.
can either include "hello" "following service lines:" or include "for y = 2 lr1" next y. want include both. how connect 2 parts? - solved!

the if match function should match sht1.range("b" & y) sht3.range("c" & i). within "y" loop, y goes 2 49, while variable should constant until loop done. should move next , on again. not working since body text includes rows variable y. - solved!

sub test() dim outapp object dim outmail object  dim sht1 worksheet dim sht2 worksheet dim sht3 worksheet  dim long dim y long dim x long  dim lr1 long dim lr2 long  set sht1 = thisworkbook.sheets("sheet1") set sht2 = thisworkbook.sheets("sheet2") set sht3 = thisworkbook.sheets("sheet3")  lr1 = sht1.cells(sht1.rows.count, "b").end(xlup).row lr2 = sht3.cells(sht3.rows.count, "c").end(xlup).row  application.screenupdating = false set outapp = createobject("outlook.application")  on error goto cleanup  = 2 lr2  if not isempty(sht3.range("c" & i))  sht3.activate sht3.range("c" & i).select  set outmail = outapp.createitem(0) on error resume next          outmail             .to = sht3.range("c" & i).offset(columnoffset:=1)             .subject = "oe input sheet " & sht3.range("c" & i) & ": service delivered = no"             .body = "hello " & activecell.offset(columnoffset:=-1).value & "." _                 & vbnewline & vbnewline & _                 "we have noticed, have indicated service deliverd = no, while service line still contains value. " _                 & vbnewline & vbnewline & _                 "we referring following service lines:" _                  y = 2 lr1                 sht1.activate                 sht1.range("b" & y).select                      if sht1.range("b" & y) = sht3.range("c" & i)                         .body = .body & vbnewline & activecell.offset(columnoffset:=1).value                     end if                  next y             .save         end          on error goto 0         set outmail = nothing     end if  next  cleanup:     set outapp = nothing     application.screenupdating = true end sub 

thanks in advance

the .body property of mailitem not append additional infomation body, entirely replaces information in body.

so when set first time "hello" portion, email body contains information. when set again in loop, contains information have set in loop.

update line in loop this:

    .body = .body & vbnewline & activecell.offset(columnoffset:=1).value 

and append new information email body.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -