Create a New Email in Outlook Using [VBA Code]

Imagine the ease of creating a new email with a simple shortcut, bypassing the usual steps, and jumping straight into what matters: composing your message.

This is not a feature of the distant future but a reality you can achieve today using VBA (Visual Basic for Applications) in Outlook.

VBA, a programming language for Office applications, can transform how you handle emails.

Let’s dive into how you can use VBA to create new emails, saving you time and enhancing your productivity.

The Magic Code: VBA for Email Creation

Sub CreateNewEmail()
    Dim mail As Outlook.MailItem
    Set mail = Application.CreateItem(olMailItem)
    With mail
        .Subject = "Your Subject Here"
        .To = "recipient@example.com"
        .Body = "Write your message here."
        .Display
    End With
End Sub

Decoding the VBA Code

Let’s break down this VBA (Visual Basic for Applications) code used in Outlook for creating a new email.

This code is composed of several steps that together automate the email creation process.

Step-by-Step Explanation of the VBA Code

Subroutine Declaration

Sub CreateNewEmail()

This line starts the definition of a new subroutine named CreateNewEmail. A subroutine in VBA is a block of code that performs a specific task.

Declaring a Variable

Dim mail As Outlook.MailItem

Dim' is short for Dimension and it’s used to declare a new variable. Here, a variable named mail is declared.

Outlook.MailItem' specifies the type of object mail is – in this case, an email item in Outlook.

Creating a New Mail Item

Set mail = Application.CreateItem(olMailItem)

This line creates a new email item in Outlook.

Application.CreateItem(olMailItem)' is a method that tells Outlook to create a new item, specifically an email (olMailItem).

Setting Up the Email

The following lines are wrapped in a With...End With block, which is a way to perform multiple operations on the mail object efficiently.

With mail
    .Subject = "Your Subject Here"
    .To = "recipient@example.com"
    .Body = "Write your message here."
    .Display
End With

.Subject = "Your Subject Here": Sets the subject of the email.

".To = "recipient@example.com": Sets the recipient’s email address.

".Body = "Write your message here.": Sets the body text of the email.

".Display: Opens the email in a window for viewing and editing. This does not send the email; it only displays it to the user.

Ending the Subroutine

End Sub

This line marks the end of the CreateNewEmail subroutine.

In summary, when this script runs, it automates the process of creating a new email in Outlook, populating the subject, recipient, and body as specified in the code, and then displays this email to the user for any final edits or to send it.

This code streamlines the process of composing an email by pre-filling certain fields.

Adding the VBA Code in Outlook

  1. Open VBA Editor: In Outlook, press Alt + F11 to open the VBA editor or go to the Developer tab
  1. Click on Visual Basic to open the VBA editor.
  1. Insert a Module: Right-click on ThisOutlookSession, select Insert, then Module.
  1. Paste the Code: Copy the VBA script above and paste it into the module.
  2. Save and Close: Save your new module and close the editor.

Executing the VBA Script

  1. Restart Outlook: Ensure the script is properly loaded.
  2. Run the Script: Press Alt + F8, select CreateNewEmail, and click ‘Run’.
  3. Compose Your Email: The new email window will open, ready for your message.

Conclusion

In summary, using VBA in Outlook for creating new emails is a smart way to boost your productivity.

While it may require some initial setup and learning, the time saved in the long run is invaluable.

Try incorporating this method into your workflow and experience a more efficient email management system.

Related Articles