Cedeq Community Forum
Keyboard Shortcut - Paste Unformatted Text in MS Word - Printable Version

+- Cedeq Community Forum (https://cedeq.com/forums)
+-- Forum: General (https://cedeq.com/forums/forumdisplay.php?fid=1)
+--- Forum: Keyboard shortcuts with AutoHotkey code (https://cedeq.com/forums/forumdisplay.php?fid=4)
+--- Thread: Keyboard Shortcut - Paste Unformatted Text in MS Word (/showthread.php?tid=41)



Keyboard Shortcut - Paste Unformatted Text in MS Word - denilama - 04-25-2018

Copying and pasting text from a web page into an MS Word document can be more trouble than it’s worth. We’ve all experienced it at least once. Changing the font, changing its size, changing its color, and changing other formatting are the usual steps involved. What if you could paste text with a macro that gets rid of all that unnecessary formatting? The ‘Paste Special’ command in MS Word has an option for this, but it takes several steps. With this little script, you can do it in one.

Need help creating a keyboard shortcut with ShortKeeper using the following AutoHotkey code? This 5-minute tutorial will help!
Critical
if WinActive("ahk_class OpusApp")
{
  ControlGet, hwnd, hwnd, , _WwG1, A
  if DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hwnd, "UInt", 0xFFFFFFF0, "Ptr", -VarSetCapacity(IID,16)+NumPut(0x46000000000000C0, NumPut(132096, IID, "Int64"), "Int64"), "Ptr*", pacc) = 0
    WordApp := ComObject(9, pacc, 1).Application
  WordApp.Selection.PasteSpecial(,,,,2)
}
else
  MsgBox 0x40040, ShortKeeper, There is no Word document window active.

The script will paste the text if the Word document is the active window and is not busy (e.g. selecting a command).

This script is optimized to be used with ShortKeeper. As such, there is no exception handling, no “Return” at the end, and variable(s) don’t need to be cleared. ShortKeeper does all of this automatically. Just copy/paste the code in the PARAM field in ShortKeeper, set your hotkey, save, and you’re ready to use your new keyboard shortcut.