PDA

View Full Version : [SOLVED:] Insert Text in EVERY email using VBA



XopieX20
03-04-2014, 06:05 AM
What I want to do is insert text in the body of EVERY email that gets sent. I dont want a signture, I want this to be spereate. So example:When I start an email, the body with already have something in it. Such as an ID #....... I'm trying to track every email by giving each terminal an ID #..... Please help and let me know if you need more info. Thanks,Brandon

westconn1
03-04-2014, 12:54 PM
the simplest solution does not involve VBA, just add to the message form design

to do by vba, probably the only solution to automate, is to add the #ID as the message is sent


Private Sub Application_ItemSend(ByVal item As Object, Cancel As Boolean)
item.Body = "Terminal #77" & vbNewLine & item.Body
End Sub
you could store the terminal number, so that it can be returned for each terminal instead of hard coding, then the same code can work for all terminals
also you may need to use the htmlbody, if the messages are fromatted as html

XopieX20
03-04-2014, 01:07 PM
the simplest solution does not involve VBA, just add to the message form designto do by vba, probably the only solution to automate, is to add the #ID as the message is sent
Private Sub Application_ItemSend(ByVal item As Object, Cancel As Boolean)item.Body = "Terminal #77" & vbNewLine & item.BodyEnd Subyou could store the terminal number, so that it can be returned for each terminal instead of hard coding, then the same code can work for all terminalsalso you may need to use the htmlbody, if the messages are fromatted as htmlhere is my code now to Auto BCC.... Can you please explain how I would put this in to use the #ID? I'm not very good at VBA and need details on how to enter it LOL..>Sorry.>Trying to learn!..................................................................... ....................Private Sub Application_ItemSend(ByVal item As Object, _Cancel As Boolean)Dim objRecip As RecipientDim strMsg As StringDim res As IntegerDim strBcc As StringOn Error Resume NextIf item.SentOnBehalfOfName = "Mailbox" ThenstrBcc = "Mailbox"End IfSet objRecip = item.Recipients.Add(strBcc)objRecip.Type = olBCCIf Not objRecip.Resolve ThenIf res = vbNo ThenCancel = TrueSet objRecip = NothingEnd Sub

westconn1
03-04-2014, 01:43 PM
just put it on the second or third lines, i can not really tell with the way your code has come out


Private Sub Application_ItemSend(ByVal item As Object, Cancel As Boolean)

Dim objRecip As Recipient
Dim strMsg As String
Dim res As Integer
Dim strBcc As String
'On Error Resume Next
item.Body = "Terminal #77" & vbNewLine & item.Body
If item.SentOnBehalfOfName = "Mailbox" Then
strBcc = "Mailbox"
Set objRecip = item.Recipients.Add(strBcc)
objRecip.Type = olBCC
If Not objRecip.Resolve Then Cancel = True
'' If res = vbNo Then
Set objRecip = Nothing
End If
End Sub

i changed your code a bit see if it works

XopieX20
03-04-2014, 01:54 PM
AMAZING! Thank you very much! Works like a charm!