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

Paste clipboard contents using VBA

Slipstick Systems

› Developer › Code Samples › Paste clipboard contents using VBA

Last reviewed on December 4, 2018     73 Comments

I need a macro that adds a specific text, plus the content of my clipboard, at the end of the subject of all messages I have selected. How do I get the content of the clipboard automatically, without first pasting it into an Input Box?

Although Outlook VBA doesn't include a paste from clipboard function directly, you can use the MSForms dataobject to transfer the clipboard contents to a string which is then called from VBA. You could also use use the Word object model to copy the message body to the clipboard.

You can also use Word's 'Keep Source Formatting' to paste formatted text into an Item Body. Code sample is at Paste formatted text using VBA

Add code similar to this to your macro:

 Dim DataObj As MSForms.DataObject
 Set DataObj = New MSForms.DataObject
 DataObj.GetFromClipboard

strPaste = DataObj.GetText(1)

The finished code will look something like the following. Note, you will need to have a reference to the Forms library in Tools, References.
Add the forms library as a reference
If you receive a "User-defined type not defined" you are missing the reference to Microsoft Forms 2.0 Object Library. If its not listed, add C:\Windows\System32\FM20.dll or C:\Windows\FM20.dll as a reference.

Sub AddtoSubject()
 Dim ex As Explorer
 Dim mail As MailItem
 Set ex = Application.ActiveExplorer
 Dim strPaste  As Variant
 
Dim DataObj As MSForms.DataObject
Set DataObj = New MSForms.DataObject
DataObj.GetFromClipboard

strPaste = DataObj.GetText(1)

If strPaste = False Then Exit Sub
If strPaste = "" Then Exit Sub

 For Each mail In ex.Selection
    mail.Subject = mail.Subject & " my text " & strPaste
    mail.Save
 Next mail
 
Set DataObj  = Nothing
End Sub

Copy to Clipboard

What about going in the other direction: copying text to the clipboard? Use PutInClipboard to capture the text.

Remember, if you receive a "User-defined type not defined" you are missing the reference to Microsoft Forms 2.0 Object Library. If its not listed, add C:\Windows\System32\FM20.dll or C:\Windows\FM20.dll as a reference.

Sub CapturetoClipbaord()
Dim oMail As MailItem
DataObj As MSForms.DataObject

    Set oMail = ActiveExplorer().Selection.Item(1)
    Set DataObj = New MSForms.DataObject
    DataObj.SetText oMail.Body
    DataObj.PutInClipboard
End Sub

Use Word Object Model to Copy (and Paste)

Current versions of Outlook use Word as the email as the email editor and can use the Word object model library to do things not normally supported in Outlook.

This sample copies the body of the selected message to the clipboard. To paste, use
objSel.PasteAndFormat (wdFormatOriginalFormatting)

Don't forget to set a reference to Word's Object model in Tools, References.

Sub CopyMessage()
    Dim objMail As Outlook.MailItem
    Dim objInsp As Inspector
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection

Set objMail = Application.ActiveExplorer.Selection.Item(1)

  If Not objMail Is Nothing Then
        If objMail.Class = olMail Then

            Set objInsp = objMail.GetInspector
            If objInsp.EditorType = olEditorWord Then
                Set objDoc = objInsp.WordEditor
                Set objWord = objDoc.Application
                Set objSel = objWord.Selection
        With objSel
            .WholeStory
            .Copy
       End With
            End If
        End If
    End If
    
    Set objMail = Nothing
End Sub

This sample shows how to paste the copied content into a new message:

    Dim objMail As Outlook.MailItem
    Dim objInsp As Inspector
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection

Set objMail = Application.CreateItem(olMailItem)
With objMail
  .To = "Alias@domain.com"
  .Subject = "This is the subject"
  .Display
End With

Set objInsp = objMail.GetInspector
If objInsp.EditorType = olEditorWord Then
    Set objDoc = objInsp.WordEditor
    Set objWord = objDoc.Application
    Set objSel = objWord.Selection
        
objSel.PasteAndFormat (wdFormatOriginalFormatting)
End If

Set objMail = Nothing
End Sub

Paste format types are below. For more information see WdRecoveryType Enumeration (Word).

NameDescription
wdChartPastes a Microsoft Office Excel chart as an embedded OLE object.
wdChartLinkedPastes an Excel chart and links it to the original Excel spreadsheet.
wdChartPicturePastes an Excel chart as a picture.
wdFormatOriginalFormattingPreserves original formatting of the pasted material.
wdFormatPlainTextPastes as plain, unformatted text.
wdFormatSurroundingFormattingWithEmphasisMatches the formatting of the pasted text to the formatting of surrounding text.
wdListCombineWithExistingListMerges a pasted list with neighboring lists.
wdListContinueNumberingContinues numbering of a pasted list from the list in the document.
wdListDontMergeNot supported.
wdListRestartNumberingRestarts numbering of a pasted list.
wdPasteDefaultNot supported.
wdSingleCellTablePastes a single cell table as a separate table.
wdSingleCellTextPastes a single cell as text.
wdTableAppendTableMerges pasted cells into an existing table by inserting the pasted rows between the selected rows.
wdTableInsertAsRowsInserts a pasted table as rows between two rows in the target table.
wdTableOriginalFormattingPastes an appended table without merging table styles.
wdTableOverwriteCellsPastes table cells and overwrites existing table cells.
wdUseDestinationStylesRecoveryUses the styles that are in use in the destination document.
Paste clipboard contents using VBA was last modified: December 4th, 2018 by Diane Poremsky
Post Views: 111

Related Posts:

  • Paste Formatted Text Using VBA
  • Change Short Date to Long Date Format in a Message
  • Copy a Contact's Mailing Address
  • Create Task or Appointment and Insert Selected Text

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. Pierre-Henry Delecourt says

    May 25, 2020 at 3:26 am

    Hi. Thanks a lot for this useful tip. I however can't fidn the reference to Microsoft Form, nor the FM20.dll library.
    I bought the Microsoft Office in September 2019. Is there a new name for this library ?
    Many thanks in advance

    Reply
    • Diane Poremsky says

      December 23, 2020 at 12:02 am

      You need to click Browse and paste the path in. C:\Windows\System32\FM20.dll 

      Reply
  2. Said says

    May 22, 2020 at 3:19 pm

    Hi Diane,

    Is there a way to paste a picture from clipboard directly using VBA?

    Thanks.

    Reply
    • Diane Poremsky says

      June 5, 2020 at 12:43 am

      No, not in Outlook. You need to use the word object. (Could probably use Excel's object model too.)

      Reply
  3. Victor says

    April 1, 2020 at 7:09 pm

    How can you save clipboard content to a folder in Word without using userform even if it is using the windows api

    Reply
    • Diane Poremsky says

      April 1, 2020 at 11:00 pm

      As far as I know, you need to use the msforms data object -

      Reply
  4. dfa says

    October 27, 2017 at 8:42 am

    Thank you for the info

    Reply
  5. Rudy says

    October 21, 2017 at 3:33 am

    This is so helpful. Thanks Admin and all the member of this page.

    Reply
  6. Lu(ky says

    August 23, 2017 at 11:56 am

    How can "Sub CopyMessage" be modified to copy text up to the first "From" in an email (copy text from the most recent email reply)?

    Reply
    • Diane Poremsky says

      August 23, 2017 at 12:21 pm

      You'd need to find it the select everything above it -
      With objSel
      .Find.ClearFormatting
      With objSel.Find
      .Text = "From: "
      .Replacement.Text = ""
      .Forward = True
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .Execute
      End With
      .MoveUp Unit:=wdLine, Count:=1
      .HomeKey Unit:=wdLine, Extend:=wdExtend

      .MoveUp Unit:=wdScreen, Count:=1, Extend:=wdExtend
      ' .WholeStory
      .Copy
      End With

      Reply
      • Lu(ky says

        August 23, 2017 at 12:36 pm

        I'm sorry, I'm having trouble implementing this new code into the older code. I appreciate the fast reply and help!

      • Diane Poremsky says

        October 8, 2017 at 11:05 pm

        I would need to see the code to help.

      • Lu(ky says

        August 24, 2017 at 10:14 am

        Unfortunately the above code does not locate the text "From"... the Sub still copies the entire email body. Any suggestion?

      • Diane Poremsky says

        October 8, 2017 at 11:04 pm

        correct, it only copies the body. you need to use oMail.sendername or oMail.senderaddress to get the frm information.

      • Lu(ky says

        August 24, 2017 at 11:57 am

        I got it to work! Thank you for your help!!

  7. Adam says

    April 6, 2017 at 1:08 pm

    Hello Diane, I'm have a need to pass the value of a highlighted text within an email body directly to a URL. so basically, I would double-click (select) on a specfic key word, click some button on my ribbon and have that run a macro to take the selected key word and insert it into a pre-defined URL. I already have the URL code working. I'm stuck trying to get the selected keyword (in the email message body) copied and passed in my code. I'm not trying to copy the entire message body. Any ideas? Thank you!

    Reply
    • Diane Poremsky says

      May 26, 2017 at 9:50 am

      Try using just .copy, removing .wholestory.
      With objSel
      .Copy
      End With

      Reply
  8. Jason Johnson says

    March 13, 2017 at 11:16 am

    Hi Diane,
    I'm trying to paste a collection of Excel cells I've copied into the clipboard into an Outlook email's .body. I'm trying to paste using destination styles so as to preserve the table grid of the cells I'm copying from my spreadsheet. While I can dump the contents unformatted easily from the clipboard, I can't seem to get anything to work using the Word references for using destination styles. I've tried playing around with the code in this post but no joy. Any help would be greatly appreciated.

    Reply
    • Diane Poremsky says

      March 16, 2017 at 1:32 pm

      You definitely need to use the word code https://www.slipstick.com/developer/code-samples/paste-clipboard-contents-vba/#word
      do you get any error messages?

      This should work to paste -
      If objInsp.EditorType = olEditorWord Then
      Set objDoc = objInsp.WordEditor
      Set objWord = objDoc.Application
      Set objSel = objWord.Selection

      objSel.PasteAndFormat (wdUseDestinationStylesRecovery)

      End If

      Valid Format types are here: https://msdn.microsoft.com/en-us/library/office/ff844915.aspx

      Reply
  9. Michele says

    January 19, 2016 at 6:05 am

    Hi Diane, I've used this code to past in the clipbord from many years ..

    Dim x As New DataObject
    x.SetText "Hi Diana"
    x.PutInClipboard

    now I've finally installed office2010 and windows10 but .. it doesn't work anymore! With CtrlV it paste just a pair of "?".
    I've just checked the presence of Microsoft Forms 2.0 Object Library and ... its ok. Any suggest to find the solution?

    Reply
    • AndyZ says

      July 21, 2016 at 10:13 pm

      Hi Diane,
      I've recently updated from Windows 7 32-bit and Office 2010 to Windows 10 64-bit and Office 2016. I am experiencing the same problem as the first commenter on this page (Michele, January 19, 2016).

      The code:
      MsgBox strContactDetails
      DataObj.SetText strContactDetails
      DataObj.PutInClipboard
      works fine, except when it doesn't. When it works I get nice text in the MsgBox which then is copied into the clipboard where I can copy it into any other application. However intermittently it doesn't work - the text is displayed properly in the MsgBox but then goes into the clipboard as two question marks. Once the issue crops up it is remedied only by rebooting the computer.

      This appears to be a known bug in Windows 64-bit builds. I found a page at https://social.msdn.microsoft.com/Forums/en-US/48e8c30c-24ee-458e-a873-a4e6e13f5926/dataobject-settext-and-putinclipboard-sequence-puts-invalid-data-hex-63-characters-in-clipboard?forum=isvvba which documents and reiterates the issue.

      Have you seen this before? I only need the unformatted text and would be fine if all formatting was stripped out.

      The full code is on your site at: https://www.slipstick.com/developer/code-samples/get-contact-details/

      Thanks as always for your expertise and willingness to share.

      AndyZ

      Reply
      • Diane Poremsky says

        July 22, 2016 at 12:05 am

        I'll see if we can do it using word code instead. (I'm on vacation so it might be a few days.)

      • Diane Poremsky says

        July 22, 2016 at 12:19 am

        Interesting problems trump vacations. :) Try this snippet for the copy part - it's longer but worked in quickie test.
        MsgBox strContactDetails

        Dim objMail As Outlook.MailItem
        Dim objInsp As Inspector
        Dim objDoc As Word.Document
        Dim objSel As Word.Selection

        Set objMail = Application.CreateItem(olMailItem)

        objMail.Body = strContactDetails
        objMail.Display
        Set objInsp = objMail.GetInspector
        If objInsp.EditorType = olEditorWord Then
        Set objDoc = objInsp.WordEditor
        Set objWord = objDoc.Application
        Set objSel = objWord.Selection
        With objSel
        .WholeStory
        .Copy
        End With

        End If
        objMail.Close (olDiscard)

        End With

        Else
        MsgBox "You need to select a Contact."
        End If

      • AndyZ says

        July 22, 2016 at 12:22 pm

        That is working wonderfully, Diane! I'll report back if I run into any problems but it has run a dozen times or so today without fail. Thank you so much! Enjoy your vacation!

    • Diane Poremsky says

      July 22, 2016 at 12:33 am

      As andyZ just pointed out, it's a bug in 64bit windows - it's not one I've experienced tho. The ?? replacement indicates an issue with font encoding.

      Pasting into a new message body and copying using word code works, although is a heck of a lot longer than 3 lines.

      Reply
  10. Fulge says

    November 23, 2015 at 9:46 am

    I'm trying to extract the first two InLineShapes of a word document on an excel macro.

    All the shapes are InLine Pictures, and I have tried to copy paste to excel to a chart then save, that works, but the quality of the picture gets greatly reduced, so I was wondering if I could just extract them directly from the word application object.

    I'm not sure how can I use the Clipboard to store he picture then save it.

    So far I have something like this:

    i = 1
    Dim DataObj As MSForms.DataObject
    Set DataObj = New MSForms.DataObject

    For Each aPict In ActiveDocument.InlineShapes
    sName = orgDocuName & "_" & i & ".jpg"
    aPict.Select
    Selection.Copy 'Is this sending to clipboard automatically??

    'Code to export/save the selected picture
    DataObj.GetFromClipboard 'Goes ok
    DataObject.GetData(1) 'Error, function doesn't exist

    i = i + 1
    Next aPict

    So I really need help on how to save the content of the clipboard (given that the Select.copy is sending the image to the clipboard) to a .jpg file (or .bmp or .png)

    Any ideas? suggestions?

    Many thanks in advance

    Reply
  11. FloRyan says

    October 21, 2015 at 1:33 pm

    Oh sorry that wasn't really accurate. Before I want to copy the content, I need to find the link in an unread email in my inbox and open it first.

    Reply
    • Diane Poremsky says

      October 26, 2015 at 1:28 pm

      That won't be so hard - you can use regex to locate it. I'll put a regex together.

      Reply
      • Diane Poremsky says

        October 26, 2015 at 2:10 pm

        This is a start - it opens a link in an email message -

        Sub GetValueUsingRegEx()
        Dim olMail As Outlook.MailItem
        Dim Reg1 As RegExp
        Dim M1 As MatchCollection
        Dim M As Match
        Dim strURL As String

        Set olMail = Application.ActiveExplorer().Selection(1)

        Set Reg1 = New RegExp

        With Reg1
        .Pattern = "(http([0-9a-z=\?:/\.&-])*)"
        .Global = False
        .IgnoreCase = True
        End With

        If Reg1.Test(olMail.Body) Then

        Set M1 = Reg1.Execute(olMail.Body)
        For Each M In M1
        strURL = M.SubMatches(0)
        Debug.Print strURL
        Next
        End If

        Set Reg1 = Nothing

        Dim oApp As Object
        Set oApp = CreateObject("InternetExplorer.Application")

        oApp.navigate (strURL)
        oApp.Visible = True

        'wait for page to load before passing the web URL
        Do While oApp.Busy
        DoEvents
        Loop
        End Sub

      • FloRyan says

        October 26, 2015 at 4:12 pm

        Thank you, you are amazing. That works just fine!

      • Diane Poremsky says

        October 26, 2015 at 5:01 pm

        I tried to insert it into a new message but i couldn't get it to work - the method i use for stationery needs to have the html saved locally.

      • FloRyan says

        October 27, 2015 at 2:17 pm

        Is there a way to open all links in all unread emails in my inbox, because right now the macro is only opening the link of an open email? Thanks in advance!

      • Diane Poremsky says

        October 27, 2015 at 3:25 pm

        it should be opening the first link in the selected message. We can loop and open all links (change .Global = True and move the lines that open IE after debug.print strurl line), but it has the potential to bring down the computer if you have a lot of links.

        From there, it's just a matter of popping it in the macro at https://www.slipstick.com/developer/code-samples/working-items-folder-selected-items/

      • FloRyan says

        October 27, 2015 at 4:48 pm

        It worked out just fine, thanks again Diane!

      • Diane Poremsky says

        October 27, 2015 at 9:30 pm

        Here's two macros - the first gets all urls in the message, the second one does all messages in a folder.
        Open All Hyperlinks in an Outlook Email Message

  12. FloRyan says

    October 21, 2015 at 1:26 pm

    Hi Diane,
    Thank you for this great website!
    How do you copy the content of a website into the body of an email?
    Best regards

    Reply
    • Diane Poremsky says

      October 26, 2015 at 12:56 am

      If the message is hTML, it often works just to select all of the page then copy and paste... or use the File, Send page by email... or if its an html page on the hard drive, you can use file > insert as text. File> Insert can be automated via a macro - https://www.slipstick.com/outlook/email/create-new-message-using-html-file-stationery/

      Using a macro is more difficult because you can't control the browser using VBA (so copy and paste is out) - the macro to insert an html file might work with a webpage - you just need to pass the page url to the macro.

      Reply
      • FloRyan says

        October 26, 2015 at 4:13 pm

        Unfortunately I couldn't figure out how to do it...

      • Diane Poremsky says

        October 26, 2015 at 10:44 pm

        What part didn't work?

      • FloRyan says

        October 27, 2015 at 4:54 pm

        It's hard to explain, but I'm kinda trying to copy a text on that webpage and that text is between 2 things, one would be a date and the other one would be a the word "next". Is there any vba code that can do that and which I can apply on every website?

      • Diane Poremsky says

        October 27, 2015 at 9:34 pm

        In outlook email or a web page? In email, as long as the date format is the same in all messages, you can use regex to find it. The same method should work for web pages but you need to be able to automate the browser using VBA so that you can find the date. That is beyond the scope of this website so i can't say for sure if you can do it from outlook.

  13. dmcmillo says

    October 21, 2015 at 1:23 am

    Hello Diane! Hopefully i have found someone that can help. I'm dealing with Access 2010. I have a form with 2 fields. Filed 1 is a text box and Filed 2 is a Bound Object Frame. My code below allows for the email to be called and information inserted into the subject and body. However my image i paste into the Bound object frame does not appear. Any ideas???

    Private Sub Complete_Click()
    Dim OL As Outlook.Application

    Dim MyItem As Outlook.MailItem

    Dim sHTML As String
    Dim sSubject As String

    Dim sTo As String
    Dim sCC As String
    Dim sBody As String

    sHTML = " Collation Team," & " " & "AutoRelease priorities have been changed to the below settings." & " " & "Reason" & " " & _
    "New Settings" & " " & "" & " "

    sSubject = "Collation AutoRelease Priority Change"
    'sTo = ""
    'sCC =""
    Call SendEMail(sTo, sCC, sSubject, sHTML)

    Reply
    • Diane Poremsky says

      October 24, 2015 at 9:58 pm

      i'm guessing you are not embedding the image correctly into the message code.

      Reply
  14. H-curious says

    September 21, 2015 at 7:45 am

    Hi Diane,

    as I said, I have a select case structure that identified the language used to compose the email and assign a signature based on the email format:
    Em is the CurrentItem (that can be a new email, a reply or a forward)
    MyLanguage is the LanguageID of the composed section of Em.
    Select Case MyLanguage
    Case 1036, 11276, 3084, 12300, 5132, 13324, 6156, 8204, 10252, 7180, 9228, 4108, 2060 'French
    Select Case Em.BodyFormat
    Case olFormatHTML
    MySignature = Environ("appdata") & "\Microsoft\Signatures\Signature_fr.htm"
    Case olFormatRichText
    MySignature = Environ("appdata") & "\Microsoft\Signatures\Signature_fr.rtf"
    Case olFormatPlain
    MySignature = Environ("appdata") & "\Microsoft\Signatures\Signature_fr.txt"
    End Select
    'This case about English language is redundant since we are using English as our default language (see Case Else)
    Case 3081, 10249, 4105, 9925, 6153, 8201, 5129, 13321, 7177, 11273, 2057, 1033, 12297 'English
    Select Case Em.BodyFormat
    Case olFormatHTML
    MySignature = Environ("appdata") & "\Microsoft\Signatures\Signature_en.htm"
    Case olFormatRichText
    MySignature = Environ("appdata") & "\Microsoft\Signatures\Signature_en.rtf"
    Case olFormatPlain
    MySignature = Environ("appdata") & "\Microsoft\Signatures\Signature_fr.txt"
    End Select
    End Select

    I have tried following Ron de Bruin's advice and look extensively on the net and I cannot find anything that would enable me to insert the selected signature (that contains images).
    MySIgnature is defined as a Variant.
    The only solution that seems to work is copying and pasting the concerned file. But as I said, I might be missing something utterly simple.

    Kind regards,

    Hacène

    Reply
  15. H-curious says

    September 20, 2015 at 1:04 pm

    Hi Diane,

    Thank you for the suggestion.
    My issue is that the files that are normally signatures, sometimes contain images.
    The file is selected based on the email language and email formatting.
    I tried various methods using .body or .htmlbody without success. I therefore opted for the simplest solution I could think off: open the file in Word copy it and paste it where I need it in the email before sending.
    If you want, I could send you privately and confidentially the frm, frx and .bas so that you could see what I am trying to do.
    Maybe I am missing something obvious and simple!

    Kind regards,

    Hacène

    Reply
    • Diane Poremsky says

      September 21, 2015 at 1:16 am

      strBody = .HTMLbody should work (but i didn't test it). did you try using insertbefore?

      Reply
  16. H-curious says

    September 17, 2015 at 8:47 am

    Hello DIane,

    I am writing an Outlook macro where I am copying formatted text from Word files at the end of an Email message.

    I am encountering several issues with this.:

    a) if Word was not opened, it refuses to close as it requests user input about the last copied item
    b) I found a temporary solution to that problem by emptying the clipboard but, the macro works only once. After that, the text from Word is not pasted into Outlook.
    c) if Word is opened, it doesn't close

    Here is the sample code

    Dim appWord As Object
    Dim opWord As Boolean

    On Error Resume Next
    'Checks if Word is opened
    Set appWord = GetObject(, "Word.Application")
    opWord = False
    'If not, opens Word
    If appWord Is Nothing Then
    Set appWord = CreateObject("Word.Application")
    opWord = True
    Err.Clear
    End If

    With appWord
    .Activate
    .Visible = True
    .WindowState = wdWindowStateNormal
    .Documents.Open MySignature
    .Selection.WholeStory
    Selection.Copy
    End With

    objSel.Collapse (wdCollapseEnd)
    objSel.InsertParagraphAfter
    objSel.PasteAndFormat wdFormatOriginalFormatting

    'Close the opened document without saving
    appWord.Close False

    'If Word was not already opened, quit the application
    If opWord = True Then
    OpenClipboard (0&)
    EmptyClipboard
    CloseClipboard
    appWord.Quit
    End If

    Set appWord = Nothing

    What am I missing?
    Thank you in advance for your help.

    Reply
    • H-curious says

      September 17, 2015 at 11:40 pm

      Hello Diane,

      Sorry for the disturbance.
      I solved the issue. appWord was an instance of Word. I added a MyFile as Word.Document and modified the code to refer to MyFile.

      The code is changed from the line With appWord as follows

      Set MyFile = appWord.Documents.Open(MySignature)

      With MyFile
      .Activate
      .Range.WholeStory
      .Range.Copy
      End With

      Em.Display

      objSel.Collapse (wdCollapseEnd)
      objSel.InsertParagraphAfter
      objSel.Paste

      With MyFile
      .Clipboard.Clear
      .Close
      End With

      If opWord = True Then
      appWord.Quit
      End If

      Thank you for you time.

      Reply
      • Diane Poremsky says

        September 18, 2015 at 12:01 am

        thanks for the update.

  17. Bhavin says

    May 4, 2015 at 12:42 am

    "Ok, so changing the body doesn't work - this does - you need to set a reference to the word object model to use it.

    Sub mail2()
    ActiveSheet.Range("A1:E10").Select
    Selection.Copy
    'This will create the email

    Dim myOutlookApp As Outlook.Application
    Dim myEmail As Outlook.MailItem
    Dim objDoc As Object, wdRn As Object
    Dim objItem As Object

    Set myOutlookApp = New Outlook.Application
    Set myEmail = myOutlookApp.CreateItem(olMailItem)
    myEmail.To = "xyz@1234.com"
    myEmail.Subject = "testmail4"
    myEmail.Display

    Set objItem = myEmail ' Application.ActiveInspector.currentItem
    Set objDoc = objItem.GetInspector.WordEditor
    Set wdRn = objDoc.Range
    wdRn.Paste

    Set objItem = Nothing
    Set myOutlookApp = Nothing

    End Sub"

    hi Diana,

    Thanks a lot for providing this piece of information. It is very helpfull. In using your above code of wordeditor pasting i am not able to enter anything using .body, as pasting replaces the body and using .body later removes pasting. Can you please provide some solution so that i can get some .body text first and then pasting and again some text.

    Reply
    • Diane Poremsky says

      September 18, 2015 at 12:07 am

      You'd normally use .body = strText & .body - i don't think you can use it with paste but you can do one of two thing.

      before pasting, add the body to a string: strBody = .body
      then add it back: .body = .body & strBody

      the other option is to use . insertbefore instead of paste. A macro that uses insertbefore is here

      Reply
  18. William says

    February 17, 2015 at 12:49 pm

    Hello! Thank you for your help.

    How would you just copy text to the clipboard in Outlook? Currently I have this macro (with just example text here) on a button on the QAT:

    Sub Info()
    MsgBox "info1" & vbCrLf & _
    "info2"
    End Sub

    I _can_ copy from the message box but I get unwanted lines and extra text besides the text I do need, which is just the "Info1" and "Info2" parts:

    ---------------------------
    Microsoft Outlook
    ---------------------------
    info1 info2
    ---------------------------
    OK
    ---------------------------

    Can you recommend code instead to copy the 2 pieces of text above to the clipboard using vb in Outlook 2010?

    Thank you!

    Reply
    • Diane Poremsky says

      February 17, 2015 at 3:09 pm

      rather than using a msgbox, use the copy to clipboard code at the bottom of the page then replace this line
      DataObj.SetText oMail.Body
      with
      DataObj.SetText "info1" & vbCrLf & _
      "info2"

      Reply
  19. Page Menyatsoe says

    October 28, 2014 at 6:09 am

    Thanks Diane, I was worried about the formatting but I see on the comments you got it sorted. If you don't mind can you kindly update the blog instead to that other readers can get to it straight away. Thanks for this information, this cannot be found on a single book. I appreciate your time and effort to educate us.

    Thanks

    Reply
  20. Ben Burrell says

    October 1, 2014 at 2:47 pm

    Hi Diane,

    I'm trying to edit the copy code to work with Excel. I'm trying to copy information from a website and bring it into the clipboard to eventually be pasted into an excel spreadsheet. Any ideas? Thank you!

    Reply
    • Diane Poremsky says

      October 2, 2014 at 8:05 pm

      Do you need formatted text or just plain text, retaining any tablet like format?

      Reply
  21. Shashank Darisi says

    September 22, 2014 at 8:19 am

    Hi Diane,

    I am trying to paste some data from an Excel Sheet into an outlok 2010 mail item as the contents. The data that I am copying has formatting like colors,table etc and I wish to retain the formatting in the mail content. Please help me on how I can achieve this. Using clipboard.GetText(1) pastes the data without the formatting :(

    Reply
    • Diane Poremsky says

      September 22, 2014 at 9:04 pm

      I know the macro here pastes formatted text: https://www.slipstick.com/developer/code-samples/paste-formatted-text-vba/

      Reply
  22. Syhn John says

    July 24, 2014 at 11:55 pm

    Success !
    You are great.
    Thanks a lot.

    Reply
  23. Syhn John says

    July 23, 2014 at 1:49 am

    Hi Diane

    It works about sending a mail ! Gr8 & thanks a lot.
    But the data copied from excel to the mail body is not in same format as that of original.
    All the cell colouring, text formating (like fields with bold/italics etc), table borders etc properties are lost.

    Could you kindly help me out with that ?
    Thanks again.

    Reply
    • Diane Poremsky says

      July 23, 2014 at 2:41 pm

      Try using myEmail.HTMLBody instead of myEmail.Body. if that doesn't work, we can merge the macro with the one at https://www.slipstick.com/developer/code-samples/paste-formatted-text-vba/

      Reply
      • Diane Poremsky says

        July 23, 2014 at 3:00 pm

        Ok, so changing the body doesn't work - this does - you need to set a reference to the word object model to use it.

        Sub mail2()
        ActiveSheet.Range("A1:E10").Select
        Selection.Copy
        'This will create the email

        Dim myOutlookApp As Outlook.Application
        Dim myEmail As Outlook.MailItem
        Dim objDoc As Object, wdRn As Object
        Dim objItem As Object

        Set myOutlookApp = New Outlook.Application
        Set myEmail = myOutlookApp.CreateItem(olMailItem)
        myEmail.To = "xyz@1234.com"
        myEmail.Subject = "testmail4"
        myEmail.Display

        Set objItem = myEmail ' Application.ActiveInspector.currentItem
        Set objDoc = objItem.GetInspector.WordEditor
        Set wdRn = objDoc.Range
        wdRn.Paste

        Set objItem = Nothing
        Set myOutlookApp = Nothing

        End Sub

  24. Syhn John says

    July 18, 2014 at 6:29 am

    Dear Diane,
    I am new to VBA & macros, so need your support.
    I do a repetitive work daily by updating values in excel sheet table cells & then copy paste that table to the body of a fresh mail & sending it to a list of fixed recipients. I have tried to automate all this above with a macro code as below.

    Sub mail2()
    '
    ' mail2 Macro
    '

    '
    Range("A1:E10").Select
    Selection.Copy
    'This will create the email
    Dim myOutlookApp As Outlook.Application
    Set myOutlookApp = New Outlook.Application
    Set myEmail = myOutlookApp.CreateItem(olMailItem)
    myEmail.To = "xyz@1234.com"
    myEmail.Subject = "testmail4"
    myEmail.Body = GetFromClipboard --
    myEmail.send
    ActiveWorkbook.Save
    MsgBox ("The email has been sent")

    End Sub

    But failed to find that email received in inbox has no contents. Why the data from clipboard is not available in the mail ?

    Kindly suggest a solution to simply make my copied contents to be available (with formating) in the mail body.

    Thanks in advance.

    Reply
    • Diane Poremsky says

      July 18, 2014 at 7:04 pm

      you need to use the msforms.dataobject - dim it, set it then get the text. This uses late binding so you don't have to set a reference to the msforms data object.

      Sub mail2()
      '
      ' mail2 Macro
      '

      '
      ActiveSheet.Range("A1:E10").Select
      Selection.Copy
      'This will create the email

      Dim myOutlookApp As Outlook.Application
      Dim myEmail As Outlook.MailItem

      Set myOutlookApp = New Outlook.Application
      Set myEmail = myOutlookApp.CreateItem(olMailItem)
      myEmail.To = "xyz@1234.com"
      myEmail.Subject = "testmail4"

      Dim DataObj As Object
      Set DataObj = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
      DataObj.GetFromClipboard

      myEmail.Body = DataObj.GetText(1)
      myEmail.Display

      Set DataObj = Nothing

      End Sub

      Reply
  25. Andreas says

    June 26, 2014 at 7:03 am

    I got the message: Compile error: Statement invalid outside Type block

    Reply
    • Diane Poremsky says

      June 26, 2014 at 8:14 am

      I'm not sure why you'd get that with out seeing the entire code sample. See https://msdn.microsoft.com/en-us/library/office/gg251561(v=office.15).aspx for an explanation of the error message.

      Reply
  26. Joe says

    September 4, 2013 at 12:08 pm

    Diane, I am trying to paste the formatted text from the clipboard into the body of an outlook 2010 email, but it keeps dropping all of the formatting nad I only get the text. Is there a way to keep the formatting from the clipboard and put it in the .Body of an email?

    Reply
    • Diane Poremsky says

      September 4, 2013 at 3:51 pm

      Try using .htmlbody instead if .body. If that doesn't work, what version of outlook?

      Reply
  27. Michael Glotzkowski says

    August 19, 2013 at 4:05 am

    Hello,
    how can I modify your script so that it adds it into the Body of a Task instead of modifying the email subject?
    I know how to copy the Outlook id of an email but when I paste it into my taks it will not create a Hyperlink as it does with your script!

    Reply
    • Diane Poremsky says

      August 19, 2013 at 9:26 pm

      You'd use objtask.body = strPaste & vbcrlf & objtask.body (assuming the object you are working with is objTask).

      I haven't tried using word commends to insert it - but that is another possibility to insert it at the top of the task body.

      Reply
      • Diane Poremsky says

        August 19, 2013 at 9:29 pm

        Actually, if you are using the code at create-task-outlookcom-local-tasks-folder, i did try different things and the body doesn't hyperlink if you are syncing with outlook.com. If you are using it with other accounts/data files, word commands should work.

        The basics of the word method is here

  28. Al Delgado says

    July 18, 2013 at 1:36 pm

    How do I add the reference to Microsoft Forms 2.0 Object Library, for C:\Windows\System32\FM20.dll

    Reply
    • Diane Poremsky says

      July 18, 2013 at 7:22 pm

      In the VBA Editor, go to Tools, Reference - if Microsoft Forms 2.0 Object Library is not listed, browse for it. (I added a screenshot of the Tools, References dialog to the page.)

      Reply

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 5

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.
  • Sync Issues and Errors with Gmail and Yahoo accounts
  • 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
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

Sync Issues and Errors with Gmail and Yahoo accounts

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

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.