PDA

View Full Version : Macro to pull up template email, need to removing signature and change "From"



Kpederson
01-14-2019, 06:32 AM
We have a Group email we send emails out with and I have a VBA code to pull those emails up, but they are always preset with my personal email and my signature. How could I add to the current code to have a different email and remove my signature.
Very new to VBA. Thanks in advance


Sub Quickturnaround()
'Open Quick Turnaround email template
Set temp = Application.CreateItemFromTemplate( _
"C:\Users\kyle-p\AppData\Roaming\" _
& "Microsoft\Templates\Quick Turnaround.oft")
temp.Display
Set temp = Nothing
End Sub

gmayor
01-14-2019, 07:11 AM
If the signature is in the template, remove it from the template and when you create a new message using that template the default signature associated with the account used to create it will be appended when you create the message..

Kpederson
01-14-2019, 09:34 AM
I have a group email and a personal work email. My signature is only attached to the Personal work email, but I don’t want a signature at all with the group email but it continues to load my personal work email. So when I open up a template email, it loads my signature even thought the template never had one. It also loads it so the "From" is from my personal and not the group email even if template is saved as "Group Email"

gmayor
01-14-2019, 09:56 PM
The account used with a template is the account set when the template is created and stored in that template. If your group mail account has a signature associated with it, that signature will be added, however if you want to retain the default signature on your group account and create a message from your template without it, then you need to create the message and remove the signature e.g.


Sub Quickturnaround()
Dim oItem As MailItem
Dim oDoc As Object
Dim oBm As Object
Dim oRng As Object
'Open Quick Turnaround email template
Set oItem = Application.CreateItemFromTemplate( _
"C:\Users\kyle-p\AppData\Roaming\" _
& "Microsoft\Templates\Quick Turnaround.oft")
Set oDoc = oItem.GetInspector.WordEditor
oItem.Display
Set oBm = oDoc.Bookmarks("_MailAutoSig")
If Not oBm Is Nothing Then
Set oRng = oBm.Range
oRng.Text = ""
End If
lbl_Exit:
Set oItem = Nothing
Set oDoc = Nothing
Set oBm = Nothing
Set oRng = Nothing
Exit Sub
End Sub

Kpederson
01-15-2019, 06:20 AM
These are actually being saved off on our Personal emailaccount templates and not the group account. So if I had a template saved on myaccount when I go to load the template it would load my default “From” and mysignature. The issue is when I go to load that template from my templates, I wantthe “From” to be from the group email and have no signature. I can’t find wherethey save off the Templates for the group email to alter the code the look upthere locations so I’m having to use my personal account rather than the groupaccount when starting.

Above Code is still giving me my Personal "From" and my signature.

gmayor
01-15-2019, 10:31 PM
The From account is saved in the template when the template is saved. It should remain in that template.

The answer then appears to be to create a blank e-mail from your template, delete the signature, change the from address, then save it as a template with the same name, overwriting original template.

The macro I posted should delete the default signature added when you create a message, but perhaps not if that signature is saved in the template as then it is part of the message text.

Kpederson
01-16-2019, 06:21 AM
So here’s how my templates are saved. I pull up a new email,once open I have to go to the Drop down box for “From:” and change it to thegroup email. I then Remove the signature and type in Subject and Body. I savethis as on oft. File. When I go to “Choose Form” and open the Body and Subjectare there, but it has re-added my Signature and reverted the “From:” back tothe personal email rather than the group email. Only thing I can think of is doI need to be an admin or something for the Group email? I’f I go to file itpulls up my personal account but shows nothing about the group account underfile. Heck I don’t even know the password for the group email. I can send pictures if that help

gmayor
01-16-2019, 07:12 AM
Does the macro remove the signature if you use it to create the message?
It should adopt the from address in the message template and certainly does here. However try the following. You will need to insert the display name of your group account.
This too works here.


Sub Quickturnaround()
Dim oItem As MailItem
Dim oAccount As Account
Dim oDoc As Object
Dim oBm As Object
Dim oRng As Object
Const strAcc As String = "account displayname" 'change as appropriate

'Open Quick Turnaround email template
Set oItem = Application.CreateItemFromTemplate( _
"C:\Users\kyle-p\AppData\Roaming\" _
& "Microsoft\Templates\Quick Turnaround.oft")
For Each oAccount In Session.Accounts
If oAccount.DisplayName = strAcc Then
oItem.SendUsingAccount = oAccount
Exit For
End If
Next
Set oDoc = oItem.GetInspector.WordEditor
oItem.Display
Set oBm = oDoc.Bookmarks("_MailAutoSig")
If Not oBm Is Nothing Then
Set oRng = oBm.Range
oRng.Text = ""
End If
lbl_Exit:
Set oAccount = Nothing
Set oItem = Nothing
Set oDoc = Nothing
Set oBm = Nothing
Set oRng = Nothing
Exit Sub
End Sub