Use AppleScript or VBA to paste unformatted text in Word for Mac

Working with formatted text copied from a stylized source such as a web page can make editing in Word for Mac laborious. For someone who does it frequently, selecting Edit > Paste Special, choosing Unformatted Text and clicking the OK button is a lengthy mundane process. This command has no quick keyboard shortcut and Apple’s feature to assign a keyboard shortcut won’t work because the command isn’t in a menu.

Fellow MVP Rich Michaels recently answered a request to make this easier. He provided a three-line snippet of Visual Basic (VBA) code for a macro that’s accessible using a keyboard command. For those unfamiliar with VBA the same is possible using AppleScript.

AppleScript or VBA?

Which is better? That depends on the need.

AppleScript is easier to read and native to Mac. Novice scripters may find the AppleScript language a challenge to learn but it uses simple English language for authoring. To have Word display a dialog on a Mac requires one line of AppleScript:

AppleScript is also available system-wide on a Mac, which means it can take information from one application and use it in another scriptable application. Unlike VBA, though, it’s not cross-platform and won’t work on Windows.

VBA is the Windows cousin to AppleScript. It’s available system-wide on Windows. It may also be more difficult for someone to learn because of its programming syntax. To have Word display a dialog using VBA requires creating a macro with the script:

This uses about the same amount of text as AppleScript but may not be as easy to understand. However, it will work on both Word for Windows as well as Word for Mac.

When deciding which scripting language is more suited to the need just keep in mind:

  • Do I need my script to work in Office for Windows too? Use VBA.
  • Do I need my script to exchange information between Word and another application? Use AppleScript.
  • Will I only use this script in Word for Mac? Use either AppleScript or VBA.

AppleScript: Paste Unformatted Text

To create an AppleScript to paste unformatted text in Word:

  1. Open AppleScript Editor, located in the /Applications/Utilities folder.
  2. Copy the following AppleScript code and paste it into the AppleScript Editor window.

    AppleScript window
  3. Choose File > Save and name the new file “Paste Unformatted Text\comU.scpt”. Select Script from the File Format drop-down menu. Click the Save button to save the file on the desktop.
    Save script
    Note the “\comU” characters at the end of the file name. This is a quick way of assigning a keyboard command when placing a script into the AppleScript menu. The letters c, o and m define the modifier keys—Control key, Option key and Command key. When pressed together the keyboard command Control-Option-Command-U will invoke the script.
  4. Open Microsoft Word and select the About This Menu command in the AppleScript menu.
    About This Menu
  5. Click the Open Folder button to open the Word Script Menu Items folder in the Finder.
    Open Folder button
  6. Drag the “Paste Unformatted Text\comU.scpt” file from the desktop to the Word Script Menu Items folder.
    Drag script to folder
  7. Return to Word and note the script now appears in the AppleScript menu with its keyboard command.
    Installed script

VBA: Paste Unformatted Text

To create a VBA macro to paste unformatted text in Word:

  1. Select Word menu > Preferences and click the Ribbon preference item.
  2. In the Customize section enable the Developer tab and click the OK button.
    Enable Developer tab
  3. Click the Developer tab in the ribbon at the top of an open Word document and then click the Macros button.
    Macros button
  4. In the Macros window enter “PasteUnformattedText” (with no spaces) in the “Macro name” field. Select “Normal (Global Template)” from the “Macros in” drop-down menu and enter “Pastes unformatted text into the current Word document” in the Description field. Click the Create button to continue.
    New macro
  5. The “NewMacros (Code)” window opens and automatically populates the name and description as well as some basic code for the new macro. Note the empty line just above “End Sub”.
    New macro code
  6. Copy the following VBA code and paste it into the empty line of the code window.
  7. Click the View Microsoft Word button in the Standard toolbar to close the macro and return to the Word document.
    View Microsoft Word button
  8. To assign a keyboard shortcut to this macro choose Tools > Customize Keyboard.
    Customize Keyboard
  9. In the Customize Keyboard window select Macros in the Categories field and then select the “PasteUnformattedText” macro in the Macros field. Click into the “Press new keyboard shortcut” field and press Control-Option-Command-U to enter the new keyboard shortcut. Click the Assign button and then click the OK button to close the window. Note the new macro and its keyboard shortcut will not appear in any menu.
    Customize Keyboard window

Using either script

Both scripts paste only unformatted text even if pictures are included in the copied data.

  1. To use either script select formatted text from another Word document or another source such as a web page. If the format of the web page makes excluding pictures or other web graphics difficult just include them.
    Copy web page
  2. Open a new or existing Word document and invoke either the AppleScript or VBA macro using the Control-Option-Command-U keyboard command. If using AppleScript, optionally choose the Paste Unformatted Text command from the AppleScript menu.
    Pasted text

Thanks to Rich Michaels for inspiring this post and providing the VBA macro code in his Microsoft Answers forum post. Thanks also to the Word:mac site on for providing the AppleScript code.

Share this:
  • Twitter
  • Facebook
  • Digg
  • StumbleUpon
  • Google Bookmarks
  • PDF
  • Print

Comments are closed.