Prior to Office 2008 , you could automatise insistent tasks and add solely new feature in Microsoft Word by using Visual Basic for Applications ( VBA ) macros . Unfortunately , Word 2008 does n’t support VBA . In its stead , Microsoft recommends that you expend AppleScript and Automator . The good news is that , with a little tinkering , almost anything you could do with a VBA macro in former version of Word , you could now do with AppleScript in Word 2008 .
There ’s defective news as well . One , Office 2008 does n’t brook the recording of AppleScripts as it once did for VBA . That intend you must write in code AppleScripts by hand . Two , you ca n’t attach AppleScripts to toolbar button . ( you may put them in a carte du jour and assign keyboard shortcut to them , though . ) And three , you ca n’t embed AppleScripts in a Word papers ( as you could do with VBA macro instruction ) ; if you want someone else to use a script you ’ve written , you ’ll have to send them the script data file along with the text file .
As examples of what you’re able to do with AppleScript in Word 2008 , I created the following scripts . They solve some canonic problem in Word ; some of them copy macro instruction I create with VBA in early rendering of Word .
Paste Plain Text: This AppleScript enables Word to paste text that adopts the style of surrounding characters, via a single menu command or a keyboard shortcut.
Paste plain text
Most word processor have an substitute Paste command — often called Paste Plain Text or Paste And Match Style — that strips the copied or make out text of its original formatting , so that when you glue it , the text strike the style of the schoolbook you ’re pasting it into . To do that in Word , after you ’ve copy or cut your text , you have to choose Edit : Paste Special , quality Unformatted Text , and tap OK ; you may assign a shortcut to Paste Special but not to the procedure as a whole .
I wanted a way to do this in Word 2008 with a single keystroke , and without having to instal any third - party software package . ( Loads of usefulness will allow you do this . ) Microsoft ’s Web site suggests one paste - as - plain - text script . It seem wonderfully unsubdivided , but there ’s a problem : unless the intromission point is at the end of the document when you course the hand , Word entrust the intromission pointbeforethe pasted text , notafter , as you would ordinarily carry when paste text .
So I made a book of my own ( see “ Code Box ” below ) . It does n’t really paste the message of the Clipboard ; rather , it simulates typing by using thetype textcommand . This method acting puts the insertion point at the end of the pasted school text , where you ’d expect it . This script work only with text . If your Clipboard contain only computer graphic , the script does nothing ; if the Clipboard contains schoolbook plus other elements , the playscript inserts only the text edition .
Enclose in HTML tags
Word is n’t the good tool for editing sore HTML code . But sometimes you may need to insert some hypertext markup language in a document . If you choose some school text and run this script ( see “ Code Box ” below ) , it encloses that text in < a>(anchor ) ticket and , as a incentive , impress the insertion breaker point between the quotation marks so that you’re able to type or paste in the uniform resource locator to which the text edition should colligate . ( you’re able to easy modify this playscript to insert unlike HTML tags . )
The lineset newPoint to ( selection jump + 9)determines the new position of the insertion full stop . ( You want the insertion point to follow the nine part in the text drawing string < a href= " . ) The lineset natural selection set out to newPointactually moves it .
Clean up text
When you glue textbook into a Word document that you ’ve copied from a Web web browser or an e - mail substance , you may find that every line has a voiceless income tax return at the destruction , and sometimes extra space . This script ( see “ Code Box ” below ) cleans up such text by remove superfluous returns and blank ; it take up that any sequence of two returns was meant to be a genuine paragraph break , while individual return should be spaces . Select the range of schoolbook you require to scavenge up , and fly the coop this script .
This hand lie in of a series of find - and - replace program line . The first replaces all double returns ( which will be real paragraph good luck ) with a placeholder graphic symbol . I used the paragraph symbolic representation ( ¶ ; option-7 ) , but you may utilise any dummy character you care , as long as it does n’t already exist in your textual matter . The 2d command replace all remaining returns with a space . The third replaces the placeholder case with single income tax return . The fourth put back all white-hot space ( any number of spaces and check ) with a single space . The fifth remove any extra space after returns .
Assign keyboard shortcuts to AppleScripts
Now that you ’ve get your AppleScript “ macros ” in Word 2008 ’s Scripts computer menu , here are two easy room to allot keyboard shortcuts to them .
organization PreferencesGo to the Keyboard & Mouse Elvis of System Preferences and select Keyboard Shortcuts . snap on the plus - sign ( + ) button at the bottom of the windowpane . From the bulge - up menu , opt Microsoft Word ( you may require to choose Other and then place it on your platter ) . Then , in the Menu Title field , type your script name exactly as it appears , including capitalization — for example , Paste Plain Text . sink in in the Keyboard Shortcut playing field , press the key(s ) you want to use as your shortcut , and tap Add .
Final thoughts
To acquire more about using AppleScript in Word , visitMicrosoft ’s Office Developers page , where you’re able to download the 526 - page PDF “ Microsoft Word 2004 AppleScript Reference ” ( most of which still applies to Word 2008 ) . If you ’re accustomed to VBA , you should also download the free PDF “ MacTech ’s Guide to Making the Transition from VBA to AppleScript ” .
Code Box
Paste Plain Text
Enclose in HTML Tags
Clean Up Text
[ Joe Kissell is the fourth-year editor program of TidBits and the source ofnumerous east - booksabout Mac OS X. ]