excel - In VBA, how can I send an email with signature and image without the direct path? -


i looking send email containing range of excel document sender's default signature (which contains image). using seems go method, shown below. originally, not email appear without changing .htm file's image src link directly relevant image. worked well, issue need solution doesn't require direct path. @ work, our computers update signature folder on startup , overwrites changes make it. have make program adaptable work computer, can't change each img src path. grateful if knew of method allow access full signature without direct path, or other workaround. thank you.

the .htm file represents signature , references image within it's source. kind of looks <img border=0 width=240 height=148 src="mycompany%20signature_files/image001.png" v:shapes="picture_x0020_1"></span><![endif]></span></a><span style='font-size:8.0pt;mso-bidi-font-size:11.0pt;font-family:"arial",sans-serif; color:#a1a0a4'>. able change src = directly path of image on computer, because gets overwritten can't use solution.

    dim outapp object     dim outmail object     application         .enableevents = false         .screenupdating = false     end     set outapp = createobject("outlook.application")     set outmail = outapp.createitem(0)     = customercontact     b = salesexec     dim ebody string     ebody = "placeholder"     ebody = cells(3, 2) & "<br>" _     & "<br>" _     & "dear, " & customerfirstname & "<br>" _     & "<br>" _     & cells(7, 2) & "<br>" _     & "<br>" _     & cells(9, 2) & "<br>" _     & "<br>" _     & cells(11, 2) & "<br>" _     & "<br>" _     & cells(13, 2)     signature = environ("appdata") & "\microsoft\signatures\"     if dir(signature, vbdirectory) <> vbnullstring         signature = signature & dir$(signature & "*.htm")     else:         signature = ""     end if      signature = createobject("scripting.filesystemobject").getfile(signature).openastextstream(1, -2).readall      on error resume next     outmail             .to = customercontact             .cc = ""             .bcc = salesexec             .subject = "welcome"              ' in place of following statement, can use ".display"              ' display e-mail message.             'or if dont want auto send.....change  .send  .display             .htmlbody = "<body style='font-family:calibri;font-size:11pt'>" _             & ebody _             & "<br>" _             & "<br>" & signature             .display     end     on error goto 0      application         .enableevents = true         .screenupdating = true     end      set outmail = nothing     set outapp = nothing 

ok thought should possible parse html , manipulate @ run-time, gave me lot more trouble anticipated, if understand correctly, need insert signature default, , think you're doing causing problem because you're manipulating .htmlbody before outlook able this. outlook add user's default signature if mailitem.display or mailitem.getinspector called before htmlbody edited.

here's simple example:

sub foo() dim signature$ dim olapp object dim olmail object set olapp = getobject(, "outlook.application") set olmail = olapp.createitem(0)  olmail.getinspector signature = olmail.htmlbody olmail.htmlbody = "<body style='font-family:calibri;font-size:11pt'>blah blah blah" _             & "<br>" _             & "<br>" & signature  olmail.display  '## verify can see signature  end sub 

try this. idea call on .getinspector (which should insert signature correctly), capture signature = .htmlbody (to append end of email later), add custom html, , append signature.

with outmail         .getinspector ' ## inserts default signature         signature = .htmlbody ' ## capture signature html         .to = customercontact         .cc = ""         .bcc = salesexec         .subject = "welcome"          ' in place of following statement, can use ".display"          ' display e-mail message.         'or if dont want auto send.....change  .send  .display         .htmlbody = "<body style='font-family:calibri;font-size:11pt'>" _         & ebody _         & "<br>" _         & signature         .display end 

how works:

outlook adds signature new unmodified messages (you should not modify body prior that) when call mailitem.display (which causes message displayed on screen) or when access mailitem.getinspector property

full code can omit of previous dealings signature , fso, etc.

dim outapp object dim outmail object application     .enableevents = false     .screenupdating = false end set outapp = createobject("outlook.application") set outmail = outapp.createitem(0) = customercontact b = salesexec dim ebody string ebody = "placeholder" ebody = cells(3, 2) & "<br>" _ & "<br>" _ & "dear, " & customerfirstname & "<br>" _ & "<br>" _ & cells(7, 2) & "<br>" _ & "<br>" _ & cells(9, 2) & "<br>" _ & "<br>" _ & cells(11, 2) & "<br>" _ & "<br>" _ & cells(13, 2)  '!---- no longer needed ----!> 'signature = environ("appdata") & "\microsoft\signatures\" 'if dir(signature, vbdirectory) <> vbnullstring '    signature = signature & dir$(signature & "*.htm") 'else: '    signature = "" 'end if  ' signature = createobject("scripting.filesystemobject").getfile(signature).openastextstream(1, -2).readall '<!-------------------------!>  outmail         .getinspector ' ## inserts default signature         signature = .htmlbody ' ## capture signature html         .to = customercontact         .cc = ""         .bcc = salesexec         .subject = "welcome"          ' in place of following statement, can use ".display"          ' display e-mail message.         'or if dont want auto send.....change  .send  .display         .htmlbody = "<body style='font-family:calibri;font-size:11pt'>" _         & ebody _         & "<br>" _         & signature         .display end on error goto 0  application     .enableevents = true     .screenupdating = true end  set outmail = nothing set outapp = nothing 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -