Outlook – What would an Outlook 2007 macro to automate Paste Special – Unformatted Text look like

microsoft-outlookmicrosoft-outlook-2007vba

I'd like to assign a macro in Outlook 2007 to a Toolbar button that would execute the equivalent of these clicks when there is formatted text in the Windows clipboard:

  1. Click the Paste icon by the bottom arrow
  2. Click the Paste Special link.
  3. Click the Unformatted Text link.

I have similar macros in Excel 2007 and Word 2007 but haven't been able to get one to work in Outlook 2007 / VBA. What would the VBA code for such a macro be?

Best Answer

With lots of help from author Sue Mosher, I have finally managed to get a macro working on Outlook 2007 to automate the mouse clicks of Paste – Paste Special – Unformatted Text! WOO-HOO!!!!

Most of what I cut and paste into Outlook email messages is formatted. Pasting with CTRL-V or by clicking the Paste button keeps that formatting intact. Clicking Paste – Paste Special – Unformatted Text isn’t a big deal, but it takes a couple of seconds every time I do it – and I do it a LOT. So this little thing will be a timesaver for me.

The VBA subroutine:

Sub Paste_Special_Unformatted()
    Dim objDoc As Word.Document
    Dim objSel As Word.Selection
    On Error Resume Next
    ' get a Word.Selection from the open Outlook item
    Set objDoc = Application.ActiveInspector.WordEditor
    Set objSel = objDoc.Windows(1).Selection
    ' now do what you want with the Selection
    objSel.PasteSpecial Link:=False, DataType:=wdPasteText
    Set objDoc = Nothing
    Set objSel = Nothing
End Sub

To get it to work, I also needed to open the VBA editor in Outlook 2007, click Tools – References, and enable the reference for Microsoft Word 12.0 Object Library. I then linked the macro to a custom button in the QAT toolbars for creating new messages and replies and it worked just fine!

I may have mentioned this before, but WOO-HOO!!!!

Thank you, Sue!

Related Question