What would an Outlook 2007 macro to automate Paste Special - Unformatted Text look like?
Solution 1:
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!
Solution 2:
It should be the same as in Word 2007:
Sub FormatText()
'
' FormatText Macro
'
'
Selection.PasteAndFormat (wdFormatPlainText)
Selection.PasteSpecial Link:=False, DataType:=20, Placement:=wdInLine, _
DisplayAsIcon:=False
End Sub
- In Outlook, point to Macro on the Tools menu, and then click Visual Basic Editor.
- In the Project window, double-click the module you want to contain the macro.
- On the Insert menu, click Procedure.
- In the Name box, type a name for the macro and click OK. Type the code you want to run in the body of the subroutine (or copy/paste it from Word)