Outlook MS Outlook - VBA for New Message

Joined
May 4, 2011
Messages
2
Reaction score
0
The following code I grabbed from a couple post here and then and compbined. My goal is two things.

1. Create New Email with template
2. Have From pre populated.

I have been able to do both of the above in individual macros separately. I am having trouble doing both in the same macro. Currently, the template loads but I cannot get the From part.

Here is the code

Sub LoadBackDateTemplate()
Dim NewMail As Outlook.MailItem
Dim objOLApp As Outlook.Application
Set objOLApp = New Outlook.Application
Set newItem = Application.CreateItemFromTemplate("C:\Documents and Settings\XBC5\Application Data\Microsoft\Templates\Security Manager Termination Violation.oft")
Set NewMail = objOLApp.CreateItem(olMailItem)
NewMail.SentOnBehalfOfName = "SYSTEMS.SECURITY"
newItem.Display
Set newItem = Nothing
End Sub

Thanks
 
Use the code you have to create the mail item from the template, then use something like this within your routine after creating the email:
With NewItem
.SenderEmailAddress = "your from (e-mail address removed)
End With

Use the object browser for more options like SenderName, SentOnBehalfOfName, etc.

If you want to see the email before it gets sent by the macro add NewItem.Display

Stoneboysteve
 
Use the code you have to create the mail item from the template, then use something like this within your routine after creating the email:
With NewItem
.SenderEmailAddress = "your from (e-mail address removed)
End With

Use the object browser for more options like SenderName, SentOnBehalfOfName, etc.

If you want to see the email before it gets sent by the macro add NewItem.Display

Stoneboysteve

The post stripped my email entry, use a valid email address when you write the script.
Stoneboysteve
 
Got it to work by doing the following:

NewMail.SentOnBehalfOfName = "SYSTEMS.SECURITY"

Change above to below

NewItem.SentOnBehalfOfName = "SYSTEMS.SECURITY"
 
Back
Top