vba - Run Script to Append Subject and Body of Email -


i [attempting to] learn how write script in outlook when category set on email:

  1. append subject " proj=5"
  2. append body 10 lines of text
  3. send email.

my goal mark email category , forward email our ticketing system.

i'm not having luck samples have found.

samples (url) have tried (copied code , updated relevant fields):

  1. append subject " proj=5"

mailitem.subject property returns string indicating outlook item. read/write.

example

item.subject = "proj=5" & item.subject 
  1. append body 10 lines of text

example

dim olbody string olbody = "<html><body><p>append body 10 lines of text</p>" & vbnewline & vbnewline & _                      "<p>append body 10 lines of text</p></html></body>" & vbnewline   olforward.htmlbody = olbody & vbcrlf & olforward.htmlbody 
  1. send / forward email

example

'//  set olforward = item.forward '// add recipent olforward.recipients.add "email@domain.com" '// send or use .dispaly  olforward.send 

run script rule

to use rule wizard, macro has have expected parameter:

example

public sub itemforward(item outlook.mailitem)  end sub 

helpful article in msdn outlook 2010 vba

complete code test on outlook 2010 vba

please make sure references set run action script (tools > references)

option explicit '// run action script  public sub itemforward(item outlook.mailitem)     dim olapp outlook.application     dim olforward mailitem     dim olbody string      set olapp = createobject("outlook.application")      '// append subject     item.subject = "proj=5 " & item.subject     item.save       set olforward = item.forward     '// add recipent     olforward.recipients.add "test@mail.com"       olbody = "<html><body><p>append body 10 lines of text</p>" & vbnewline & vbnewline & _                          "<p>append body 10 lines of text</p>" & vbnewline & _                          "<p>append body 10 lines of text</p>" & vbnewline & _                          "<p>append body 10 lines of text</p>" & vbnewline & _                          "<p>append body 10 lines of text</p>" & vbnewline & _                          "<p>append body 10 lines of text</p>" & vbnewline & _                          "<p>append body 10 lines of text</p>" & vbnewline & _                          "<p>append body 10 lines of text</p>" & vbnewline & _                          "<p>append body 10 lines of text</p>" & vbnewline & _                          "<p>append body 10 lines of text</p></html></body>" & vbnewline       '// forward email     olforward.htmlbody = olbody & vbcrlf & olforward.htmlbody     '// send or use .dispaly     olforward.send     set olapp = nothing     set olforward = nothing end sub 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -