Word Create Outlook Email with Selected Text | VBA Macro #29

Share on facebook
Share on twitter
Share on linkedin

Macro Intro

Have you ever been prompted to send a follow up email while working in Word? Maybe you are reviewing a meeting agenda or reading a final draft for a new company policy. You can navigate to Outlook create a new email and copy paste the necessary text in. This takes a bit of time and isn’t very efficient. Instead try using our Word Macro Create Outlook Email with Selected Text! This macro will generate an Outlook email directly out of Word pulling in any text you have selected into the Email Body. Simply select some text and run this Word macro. You will see an Outlook email appear confirming that this macro has successfully run. The text you selected will be populated in the body making it easy to reference when drafting your email. By Default, the Email Subject will be populated with the text [Follow Up] Active Document’s Name. You can easily add in To & CC Recipients if you are routinely email the same people! This macro is a better way to generate a follow up email helping you get a quicker response. Instead of writing reminders on Post-it notes start using this macro Create Outlook Email with Selected Text today!

See it in Action

Watch this video to see this macro in action.

Code

Here is the code for this macro. Make sure the following References are setup before running it: Visual Basic For Applications, Microsoft Word 16.0 Object Library
***Recent Code Updates
12.14.2021 Update to allow for three different formatting behavior when the Word text is transferred to the Outlook Email. Using the NewEmail.HTMLBody variable won’t display color and retain line breaks. Using the NewEmail.HTMLBody variable won’t display color but will retain line breaks. To retain “all” the formatting from Word (like color, bold, italics, etc.) then update to use NEW Variables so Word text is selected, copied and pasted into the Outlook Email. This is the NEW default behavior for this macro. The cool thing about this option is it also allows for the selection, copying, and pasting of images from Word to the generated Outlook email!
03.17.2022 Updated to not generate an error when nothing is selected in Word. The best way to determine this was to look at the current length of the selection in Word. Regardless of what you have selected it is a 1, so simply looked to see if any selected had a length greater than 1.
Copy the Code
'Leverage & Lean "Less Clicks, More Results"
Sub CreateEmailwithSelectedTextFreeMacro()
' Means variable is in use
Dim Body As Word.Document '
Dim NewEmail As Object '
Dim OutlookApp As Object '
Dim Selection As Word.Selection '
  
On Error GoTo LeverageLean
  
Set OutlookApp = CreateObject("Outlook.Application")
Set NewEmail = OutlookApp.CreateItem(olMailItem) 'Create a NEW Outlook Email
  
NewEmail.To = "" 'Update to include To Recipients in NEW Outlook Email
NewEmail.CC = "" 'Update to include CC Recipients in NEW Outlook Email
NewEmail.Subject = "[Follow Up] " & ActiveDocument.Name 'Update Subject in NEW Outlook Email
'NewEmail.HTMLBody = "<HTML><BODY><span style=""font-family : Calibri;font-size : 11pt"">" & Word.Selection.Text & "</span></BODY></HTML>" 'Text selected won’t display color and retain line breaks
'NewEmail.Body = Word.Selection.Text 'Text selected won’t display color but will retain line breaks
NewEmail.Display 'Display NEW Outlook Email

If Len(Word.Selection) > 1 Then
Word.Selection.Copy 'Copy selected text in Word
Set Body = OutlookApp.ActiveInspector.WordEditor
Set Selection = Body.Application.Selection
Selection.Paste 'With the NEW Outlook Email selected paste the text selected in Word. Retains "all" the formatting from Word like color, bold, italics, even include images selected!
End If
  
Set NewEmail = Nothing
Set OutlookApp = Nothing
  
Exit Sub
  
LeverageLean:
MsgBox (Err.Number & " - " & Err.Description & vbNewLine & vbNewLine & "Don't hesitate to email me: brentschneider@leveragelean.com")
    
End Sub
'Stay Awesome

Insider Content

Here is the Insider code for this macro. This macro will reference an Excel Workbook to display selection options to pull in specific recipients into the To & CC fields of the Outlook email created. Similar to the Outlook Looping In | VBA Macro #28. Your selection option will also be included in the Subject field of the Outlook Email. Make sure the following References are setup before running it: Visual Basic For Applications, Microsoft Word 16.0 Object Library, Microsoft Excel 16.0 Object Library

Customization

These segments of code can be customized to personalize this macro.
The NewEmail.To code segment update = “” to listed out email addresses (separated by 😉 that you want to populate into the NEW Outlook Email’s To field.
The NewEmail.CC code segment update = “” to listed out email addresses (separated by 😉 that you want to populate into the NEW Outlook Email’s CC field.
By Default the NEW Outlook Email Subject will populate with [Follow Up] and the Word Document Name. If you want this to be populated with something else you can update this text here.
This code segment is a comment but this can be removed so the Word Document Text selected populates into the NEW Outlook Email with just text (no colors or line breaks)
This code segment is a comment but this can be removed so the Word Document Text selected populates into the NEW Outlook Email with just text and line breaks (no colors)

First time using VBA?

The Developer Tab is an additional section of the ribbon when activated allows you access to Visual Basic in Applications like Access, Excel, Outlook, PowerPoint, Word.
Setup Now
Once the Developer Tab is available you will have the capability to update your security to allow Macros to run in the current application.
Setup Now
A sub of code is a collection of objects and variables. For the code to successfully run a library of references needs to be set.
Setup Now
Subscribe as an Insider to receive additional rights.
If you like our content and want to show your support tip us here!

Contact Us

Looking to improve your computer processes?
Leverage & Lean is here to help!

Powered By MemberPress WooCommerce Plus Integration

Free Macro

Start creating Less Clicks, More Results today!