If you always need to change email stationery to a specific one when sending emails to a certain person, why not configure Outlook to auto do this? This post will guide you to achieve this feature via VBA.
Outlook allows you to set specific stationery as the default one for all new html emails. However, at times, you may want to apply another when sending emails to a specific person. For instance, to send emails to your boss, you had better use more official stationery. In this situation, it is pretty tedious and troublesome for you to change the stationery manually every time. Hence, why don’t you let your Outlook auto accomplish this task? Now, in the followings, we will teach you how to get it with VBA code.
Auto Apply a Specific Stationery when Sending Emails to a Specific Person
- To start with, launch your Outlook application.
- Then, tap on “Alt + F11” keys to access VBA editor.
- Next, in the new “Microsoft Visual Basic for Applications” window, copy the following VBA code into the “ThisOutlookSession” project.
'Occurs when click "Send" button Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) Dim objMail As Outlook.MailItem Dim objRecipient As Outlook.Recipient Dim strStationeryFile As String Dim objFileSystem As Object Dim objTextStream As Object Dim strTextStream As String Dim strHTMLBody As String If TypeOf Item Is MailItem Then Set objMail = Item If objMail.Recipients.Count = 1 Then Set objRecipient = objMail.Recipients.Item(1) 'Change the recipient address as per your needs If objRecipient.Address = "email@example.com" Then 'Change the path to the specific stationery file strStationeryFile = CStr(Environ("USERPROFILE")) & "\AppData\Roaming\Microsoft\StationeryShelly.htm" Set objFileSystem = CreateObject("Scripting.FileSystemObject") Set objTextStream = objFileSystem.OpenTextFile(strStationeryFile) strTextStream = objTextStream.ReadAll 'Insert the stationery into the current email With objMail strHTMLBody = .HTMLBody .HTMLBody = strTextStream .HTMLBody = .HTMLBody & strHTMLBody End With End If End If End If End Sub
- After that, close the current window.
- At present, you can take a shot.
- First off, compose an email sent to the specific person.
- Then, click the “Send” button.
- After the email being sent out, you can go to “Sent Items” folder to find it.
- Open it and you will see that the specific stationery has been used in this email.
Resort to an External Tool in Case of Outlook Damage
Even though Outlook provides users with a great amount of excellent functions, it still cannot be free of vexing errors or crashes. Fortunately, it comes packed with an inbox repair tool – Scanpst.exe. This utility is capable of solving most of small problems in Outlook. Nevertheless, in the event of serious Outlook corruption, it won’t be a lot of help. At that time, your resort should be a more experienced and trustworthy tool, say DataNumen Outlook Repair.
Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupted sql and outlook repair software products. For more information visit www.datanumen.com