Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook macro to change FROM field and signature 2

Status
Not open for further replies.

gezster

Technical User
Jul 12, 2010
12
GB
Hello,

I'm trying to find a way of creating a macro that will change the new/replied email's FROM field to read a different address, and change the signature to the corresponding one for that address.

IE: User BOB has full access to the SALES@ email address.
When he replys to a sales enquiry I need to FROM address to read SALES@, not BOB@, and the Signature to be set to the SALE dept Sig, not Bob's own.

Were using a mixture of Outlook 2003/2007 ( mostly 2003 )

Thanks
 
Hi,

this should be fairly easy - at least with OL 2003; I've no idea how 2007 will behave with this though.

Code:
Dim mi As MailItem, sj As String, re As MailItem

If ActiveInspector.CurrentItem.Class = olMail Then
    Set mi = ActiveInspector.CurrentItem
    sj = mi.Subject
    Set re = mi.ReplyAll
    re.From=Replace(re.From, "BOB@", "SALES@")
    re.Subject = "Re: " & sj
    re.Display
End If
;-)

Cheers,
MakeItSo

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Hi,
Thanks for the quick reply.
That seems to cause an error in 2007, speficially at the line :-

re.From=

the error is :-

Run-Time error '438':

Object dosn't support this property or method.

Also, how would i amend you code to include the addition of the required signature?

Thanks
 
I've figured out the From field error. If I use :-0

SentOnBehalfOfName =

instead, it works in 2007.
Now, would that still work in 2003 ?
 
Sorry, my bad. I've typed that From just like that without testing... [blush]
SentOnBehalfOfName is used when sending the E-mail as a substitute. That's not what you want.
Instead, use:
Code:
re.SenderEmailAddress=Replace(re.SenderEmailAddress, "BOB@", "SALES@")

For the signature, I cannot tell exactly as this is now part of the body text.
Code:
re.Body=replace(re.Body, youroldsigline, yournewsigline)
might work but if you include your entire sig line in that variable.
That however also depends on your mail format. When using HTML mail for example, there will be additional "<br/>" tags in that line, as well as perhaps formatting tags.

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
FYI ,

this is my coding so far ( still having trouble putting an HTML signature at the bottom though. Any Thoughts ? )

<CODE>
Sub ReplyTVS()

Dim mi As MailItem, sj As String, bd As String, re As MailItem

If ActiveInspector.CurrentItem.Class = olMail Then
Set mi = ActiveInspector.CurrentItem
sj = mi.Subject
bd = mi.Body

Set re = mi.ReplyAll
re.BodyFormat = olFormatHTML
re.SentOnBehalfOfName = "The Vineyard Reservations"
're.From="The Vineyard Reservations"
re.Subject = "Re: " & sj
re.Body = "Gerald" & vbCrLf & vbCrLf & bd
re.Display
End If
End Sub
<CODE>
 
sorry to post so quickly after my previous one, but I've found the way to add HTML signatures (thanks to Ron de Bruin),....but it creates another problem ....

{code}
Sub ReplyTVS()

Dim mi As MailItem, sj As String, bd As String, re As MailItem
Dim SigString As String
Dim Signature As String
Dim spacer As String

If ActiveInspector.CurrentItem.Class = olMail Then
Set mi = ActiveInspector.CurrentItem
sj = mi.Subject
bd = mi.Body
' use first string for XP. second string for vista and Windows 7

'SigString = "C:\Documents and Settings\" & Environ("username") & _
"\Application Data\Microsoft\Signatures\Mysig.htm"

SigString = "C:\Users\" & Environ("username") & _
"\AppData\Roaming\Microsoft\Signatures\Sig_Vineyard.htm"

spacer = "-----Original Message-----"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If

Set re = mi.ReplyAll
re.BodyFormat = olFormatHTML
re.SentOnBehalfOfName = "The Vineyard Reservations"
're.From="The Vineyard Reservations"
re.Subject = "Re: " & sj
re.HTMLBody = Signature & spacer & bd
re.Display
End If
End Sub
Function GetBoiler(ByVal sFile As String) As String
'Dick Kusleika
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function
{code}

Right "from" address, right signature,...but the orignal emails format gets ....lost when i run the macro.
No line breaks etc.
I'm sure this is a "school boy error" but I can't see it.
Can someone point out where i'm going wrong please.

Thanks
 
Replace this:
bd = mi.Body
with this:
bd = mi.HTMLBody

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
BRILLANT.

Thank you everyone for helping.

I hope this thread helps others
 
Hi, Just one more thing,

This works GREAT if the message is opened, but not if its being read in the preview / reading pane.
What would I need to change to make it open the selected email , and then change the from field etc ?

Thank
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top