• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Paste Formatted Text Using VBA

Slipstick Systems

› Developer › Code Samples › Paste Formatted Text Using VBA

Last reviewed on December 4, 2018     10 Comments

A visitor to OutlookForums, PGilm is using VBA to create a meeting request and wanted to paste formatted text into the body.

While it's fairly straightforward if you are pasting into a mail item, you can't use HTMLBody or olHTMLFormat with non-mail items. You can use Word's 'Keep Source Formatting' paste command, provided you are using Word as the email editor. (It's the only editor in Outlook 2007 and newer.)
Keep source formatting command

You will need to set a reference to the Word Object Model in the VB editor's Tools, References menu.

This sample code creates an appointment form with the clipboard contents pasted in the appointment body.

To remove the formatting, use wdFormatPlainText.

Sub PasteFormattedClipboard()
    On Error Resume Next
        Dim olCal: Set olCal = Application.CreateItem(1)
        olCal.Subject = "Testing " & Now
        olCal.Location = "Here"
olCal.Display
     
Dim objItem As Object
Dim objInsp As Outlook.Inspector
Dim objWord As Word.Application
Dim objDoc As Word.Document
Dim objSel As Word.Selection


Set objItem = olCal ' Application.ActiveInspector.currentItem
Set objInsp = objItem.GetInspector
Set objDoc = objInsp.WordEditor
Set objWord = objDoc.Application
Set objSel = objWord.Selection


objSel.PasteAndFormat (wdFormatOriginalFormatting)
'objSel.PasteAndFormat (Word.WdRecoveryType.wdFormatOriginalFormatting)


Set objItem = Nothing
Set objInsp = Nothing
Set objDoc = Nothing
Set objWord = Nothing
Set objSel = Nothing
End Sub

PasteAndFormat members

The following is a list of the PasteAndFormat options available to use. wdFormatOriginalFormatting and wdFormatPlainText are the most frequently used paste formats that would cover most situations, however you can use other paste formats.

Member nameDescription
wdSingleCellTextPastes a single cell as text.
wdSingleCellTablePastes a single cell table as a separate table.
wdListContinueNumberingContinues numbering of a pasted list from the list in the document.
wdListRestartNumberingRestarts numbering of a pasted list.
wdTableInsertAsRowsInserts a pasted table as rows between two rows in the target table.
wdTableAppendTableMerges pasted cells into an existing table by inserting the pasted rows between the selected rows.
wdTableOriginalFormattingPastes an appended table without merging table styles.
wdChartPicturePastes an Excel chart as a picture.
wdChartPastes a Microsoft Excel chart as an embedded OLE object.
wdChartLinkedPastes an Excel chart and links it to the original Excel spreadsheet.
wdFormatOriginalFormattingPreserves original formatting of the pasted material.
wdFormatSurroundingFormattingWithEmphasisMatches the formatting of the pasted text to the formatting of surrounding text.
wdFormatPlainTextPastes as plain, unformatted text.
wdTableOverwriteCellsPastes table cells and overwrites existing table cells.
wdListCombineWithExistingListMerges a pasted list with neighboring lists.
wdUseDestinationStylesRecoveryUses the styles that are in use in the destination document.

More Information

WdRecoveryType Enumeration

Paste Formatted Text Using VBA was last modified: December 4th, 2018 by Diane Poremsky
Post Views: 28

Related Posts:

  • Add the forms library as a reference
    Paste clipboard contents using VBA
  • Merge to email using only Outlook
  • Create Task or Appointment and Insert Selected Text
  • Use Word Macro to Apply Formatting to Email

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Comments

  1. Richard says

    June 2, 2017 at 5:00 am

    In case you are pasting a table from Excel into an Outlook email the below has some additional text so it will autofit the table immediately.
    Sub PasteFormattedClipboard()
    Dim olCal: Set olCal = Application.CreateItem(1)
    Dim objItem As Object
    Dim objInsp As Outlook.Inspector
    Dim objWord As Word.Application
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection

    Set objItem = olCal ' Application.ActiveInspector.currentItem
    Set objInsp = objItem.GetInspector
    Set objDoc = objInsp.WordEditor
    Set objWord = objDoc.Application
    Set objSel = objWord.Selection

    objSel.PasteAndFormat (wdFormatOriginalFormatting)

    Dim aTbl As Word.Table
    For i = 1 To objSel.Tables.Count()
    Set aTbl = objSel.Tables.Item(i)
    aTbl.Columns.PreferredWidth = Unchecked
    aTbl.Columns.PreferredWidthType = wdPreferredWidthAuto
    Next

    Set objItem = Nothing
    Set objInsp = Nothing
    Set objDoc = Nothing
    Set objWord = Nothing
    Set objSel = Nothing
    End Sub

    Reply
  2. Jimmy says

    July 9, 2016 at 3:06 am

    Dear Diane,

    Thanks for your comments they are REALLY helpful!!!
    Just wondering is it possible to copy email body to clipboard and preserve the formatting? I tried PutInClipboard but it converts anything into plain text.

    Thanks!!!
    Jimmy

    Reply
    • Diane Poremsky says

      October 12, 2016 at 12:20 am

      Yes, but you need to use word objects - see https://www.slipstick.com/developer/code-samples/paste-clipboard-contents-vba/#word for the code sample.

      Reply
  3. Shashank Darisi says

    October 2, 2014 at 4:02 am

    Oh!! That's really unfortunate! :( Well, I was searching through the net for the solution to my problem and it seems there's only one widely accepted solution to achieve it. It's a helper function by a guy named Ron De Bruin and it works perfectly! :)

    https://www.rondebruin.nl/win/s1/outlook/bmail2.htm

    Reply
  4. Shashank Darisi says

    September 23, 2014 at 5:08 am

    Hi, this is a really helpful article!! Thanks so much for sharing this :)
    One question though, is the above code to be used in Outlook VBA or in Excel VBA ?

    Reply
    • Diane Poremsky says

      September 23, 2014 at 8:07 am

      Outlook. Are you working with a macro in Excel already? It's possible to do with (different) code from excel too.

      Reply
      • Shashank Darisi says

        September 23, 2014 at 9:44 am

        Yes :( I already have a macro in Excel and after doing some stuff, I have a range of cells which need to be emailed via outlook and I need the data formats to be retained... any suggestion? :)

      • Diane Poremsky says

        October 2, 2014 at 1:21 am

        Just a range and not a whole sheet? A whole sheet could use the "wordmail" feature where you add an email header to excel.

        I've been working on some code samples to send a range... then lost them when Outlook crashed before I hit save. :(

      • DAVID says

        April 12, 2016 at 6:21 pm

        I saw Ron's code. It works with Outlook mail messages but not with Meeting invites.
        This is probably because meetings cant be HTML. Is there a way to alter Ron's code for meeting invites?

      • Diane Poremsky says

        April 12, 2016 at 9:13 pm

        Does it not work at all with invites or is the text ugly?
        This line: Set OutMail = OutApp.CreateItem(0) tells it to create email. That needs changed to 1 for meetings.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 31 Issue 3

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Error Opening iCloud Appointments in Classic Outlook
  • Opt out of Microsoft 365 Companion Apps
  • Mail Templates in Outlook for Windows (and Web)
  • Urban legend: Microsoft Deletes Old Outlook.com Messages
  • Buttons in the New Message Notifications
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Error Opening iCloud Appointments in Classic Outlook

Opt out of Microsoft 365 Companion Apps

Mail Templates in Outlook for Windows (and Web)

Urban legend: Microsoft Deletes Old Outlook.com Messages

Buttons in the New Message Notifications

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2026 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.