Thursday, April 26, 2018

How can I use the keyboard to choose how to paste text in MS Word?


While using a word processor I prefer to user the keyboard almost exclusively, but when pasting text in MS Word I seem forced to use the mouse. I can find no way to specify how to treat formatting (keep source / match destination / text only) on a one-off basis without using the mouse (distracting and slow) or altering my default settings (even worse).


Is there a way to do this? It seems to me I need either a keyboard shortcut to enter the Paste Options dialogue after pasting or a different command that I can use to specify the formatting option. I looked at Paste Special, but that only seems to provide one relevant option, namely ‘text only’ (Unformatted Text), while I want ‘keep’ or ‘match’ as well.


I am using MS Word 2007, but an answer applying to other versions would obviously be more generally useful.


P.S. I use MS Office’s Dutch UI for compatibility with colleagues, so various keys and texts above may be inaccurate.


Answer



Further to the useful answer by Lernkurve, I conclude that ‘Paste Special…’ does not do the job, while mapping keystrokes to macros created from the ‘paste mode’ dialogue does. Since his first two options apply Word 2013 and up, anyone stuck on 2007 will have to create and map macros.


Recording Macros


To record macros, you need the Developers tab enabled in the ribbon, in Word Options/Popular Options.


Macros for the Paste Modes


The macros needed to do the job, recorded by entering the choice menu after pasting are:


Sub PasteOriginal()
' Paste with option ‘original formatting’
Selection.PasteAndFormat (wdFormatOriginalFormatting)
End Sub
Sub PasteMatching()
' Paste with option ‘match destination’
Selection.PasteAndFormat (wdFormatSurroundingFormattingWithEmphasis)
End Sub
Sub PasteText()
' Paste with option ‘only text’
Selection.PasteAndFormat (wdFormatPlainText)
End Sub

I mapped these to Ctrl+Alt+Shift+(<|||>) for keep format, text only and merge format respectively. I chose the modifier keys Ctrl+Alt+Shift to avoid clashes with predefined mappings, while (<|||>) suggested to me looking back (to the source format), neutral and looking forward (to the destination format), even if those are not really what happens.


Meaning of the Options


The meaning of the options is described as follows on MSDN (I have not tested this thoroughly):



  • Keep source formatting (wdFormatOriginalFormatting): “Preserves original formatting of the pasted material” – I presume this includes styles, but wonder what happens if style names clash. I presume that all current formatting is ignored.

  • Merge formatting (wdFormatSurroundingFormattingWithEmphasis): “Matches the formatting of the pasted text to the formatting of surrounding text” – I believe this means that the characters from the source and any emphasis (bold, italic, _ underlining _) are inserted in the current formatting, while all other original formatting is ignored.

  • Keep Text only (wdFormatPlainText): “Pastes as plain, unformatted text.” – Only the characters from the source are inserted, in the current formatting.


Options in Paste Special


I investigated the options in Paste Special…, recording macros for each option, as in the screenshot of the dialogue in Lernkurve’s answer. Some of them seemed to behave as keep format (sometimes doing odd extra things), others as text only, but none as merge format. (To get all options I had to paste text with some extra formatting, otherwise I just got two options; my set of options included “Picture (Windows Metafile)”, not in his screenshot.)


These were the results:


Sub SpecialPasteDoc() ' MS Office Word-document object
Selection.PasteSpecial Link:=False, DataType:=wdPasteOLEObject, Placement _
:=wdInLine, DisplayAsIcon:=False
End Sub
Sub SpecialPasteRTF() ' Formatted text (RTF)
Selection.PasteAndFormat (wdPasteDefault)
End Sub
Sub SpecialPastePlain() ' Unformatted text
Selection.PasteAndFormat (wdPasteDefault)
End Sub
Sub SpecialPastePic() ' Picture (Windows Metafile)
Selection.PasteAndFormat (wdPasteDefault)
End Sub
Sub SpecialPastePicEnhanced() ' Picture (Enhanced Metafile)
Selection.PasteAndFormat (wdPasteDefault)
End Sub
Sub SpecialPasteHTML() 'HTML Format
Selection.PasteSpecial Link:=False, DataType:=wdPasteHTML, Placement:= _
wdInLine, DisplayAsIcon:=False
End Sub
Sub SpecialPasteUnicodeText() ' Unformatted Unicode Text
Selection.PasteSpecial Link:=False, DataType:=20, Placement:=wdInLine, _
DisplayAsIcon:=False
End Sub

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...