Search code examples
vbaemailoutlookoutlook-2010

Trying to create a button in outlook 2010 that replys to highlighted email/open email w/ static text and cc's an email address


Everything seems to work except adding the email address to the cc. The account I am testing with may be hidden from the GAL.

Also is there a way to add the User's display name to the body text i.e. Great Job (dynamic name i.e. Ted i.e. email sending i am replying to)! I loved your work . . .

Using windows 7 enterprise w/ outlook 2010 professional Plus 32bit and exchange 2010.

Thanks! Code below

Sub GoodJob()

Dim m As MailItem 'object/mail item iterator
Dim recip As Recipient 'object to represent recipient(s)
Dim reply As MailItem 'object which will represent the reply email

'Loop over each SELECTED item:
For Each m In Application.ActiveExplorer.Selection
If m.Class = olMail Then
Set reply = m.reply

'Adds a "direct replies to" address:
'Set recip = reply.ReplyRecipients.Add("g@g.com")
Set recip = reply.ReplyRecipients.Add("someperson@a.net")
recip.Type = olCC

'adds Subject "Great Job! I loved your work on this Project" to email
 reply.Subject = "Great Job ! I loved your work on this Project"

'Adds Body of text to email
reply.Body = "Your awesomeness has been shared with Driver X" & vbLf &   m.Body



reply.Save 'saves a draft copy to your SENT folder
reply.Send

End If
Next

End Sub

Solution

  • Not ReplyRecipients in this case just Recipients.

    Set recip = reply.Recipients.Add("someperson@a.net")