Friday, May 13, 2011

microsoft word spellcheck automation clipboard

An neat microsoft word windows automation script I picked up in a PC Mag article by Neil Rubenking.
I used to bring up Microsoft Word, paste the text into it, spell-check, and paste the corrected text back into the browser. Then I realized there was an easier way. Save the following as c:\temp\spellcheck.js:
oShell= new ActiveXObject("WScript.Shell");
oShell.SendKeys( "^c" ); // copy
oWord= new ActiveXObject("Word.Application");
oWord.Visible= true;
oWord.Documents.Add();
oWord.Selection.Paste();
oWord.ActiveDocument.CheckSpelling();
oWord.Selection.WholeStory();
oWord.Selection.Copy();
oWord.ActiveDocument.Close(0);
oWord.Quit();
var nRet= oShell.Popup( 
"Apply changes?\nClick OK to replace all selected text.",
0,
"Spell Check Complete",
33 );
if ( nRet == 1 ) {
oShell.SendKeys( "^v" ); // paste
}
Drag the file from Windows Explorer to the Links bar in IE to create a shortcut to the script. Right-click the shortcut, choose Rename, and name it Spell Check. Now when you're entering text in any Web page, you can highlight the text and click the Spell Check button. Word comes up and does a normal, interactive spell check, closing when finished.

No comments:

Post a Comment