How to suppress MS Word window in spell check scri

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
ackrite
Posts: 2
Joined: Mon Jun 04, 2007 9:41 pm

How to suppress MS Word window in spell check scri

Post by ackrite »

Ok so I'll admit, I dont know vbs, but have a little background in some other languages, so I have a little understanding in scripting. Below is a spell check(with MS Word) script that I found on the net the other day. I made a few changes to it and now it works just like I want it to, except that it flashes/pops up MS Word for a second or two after you make the spelling changes. Is there anyway to suppress MS Word or stop it from flashing at all? Thanks for any help on this.... How the script works: -copy word or set of words to the clipboard -run script -make changes with MS Word spell checker -then the correct spellings of the word(s) are placed back to the clipboard


Dim oWD, RangeOriginal, RangeCorrected, Cnt, Status Set oWD = WScript.CreateObject("Word.Application") oWD.Visible =false oWD.Documents.Add On Error Resume Next oWD.Selection.Paste If err.number<>0 then MsgBox "Clipboard was Empty" oWD.ActiveDocument.Close wdDoNotSaveChanges oWD.Quit Set oWD=Nothing Set oWD=Nothing WScript.Quit End If ' Set RangeOriginal=oWD.ActiveDocument.Range(0,oWD.Selection.End) If oWD.CheckSpelling(RangeOriginal)=False Then oWD.ActiveDocument.CheckSpelling Set RangeCorrected = oWD.ActiveDocument.Range(0,oWD.Selection.End) RangeCorrected.copy ' If RangeCorrected.Words.Count>7 Then Cnt=RangeCorrected.Words.Count Status= "The text beginning with: "&_ RangeCorrected.Words.Item(1)&" "&RangeCorrected.Words.Item(2)&" "&_ RangeCorrected.Words.Item(3)&"....."&vbCRLF&"and ending with: ....."&_ RangeCorrected.Words.Item(Cnt-2)&" "&RangeCorrected.Words.Item(Cnt-1)&_ " "&RangeCorrected.Words.Item(Cnt)&vbCRLF End If ' Else Status= "All words in the clipboard were spelled correctly" MsgBox Status End If ' oWD.ActiveDocument.Close wdDoNotSaveChanges oWD.Quit Set oWD=Nothing

User avatar
jhicks
Posts: 1789
Joined: Sun Jan 21, 2007 11:31 pm

How to suppress MS Word window in spell check scri

Post by jhicks »

With the visible property set to False you shouldn't see the app, so I'm a little puzzled. I see you are using Word constansts like wdDoNotSaveChanges. Are these defined somewhere else in your script?

User avatar
ackrite
Posts: 2
Joined: Mon Jun 04, 2007 9:41 pm

How to suppress MS Word window in spell check scri

Post by ackrite »

With the visible property set to False you shouldn't see the app, so I'm a little puzzled. I see you are using Word constansts like wdDoNotSaveChanges. Are these defined somewhere else in your script?

This is the complete script, so they are not defined elsewhere. Not sure if this will help any, but this is where I found the script http://www.pcnineoneone.com/tweaks/scripts8.html. Like I said I made a few changes to it to work the way I like, and it does except for the MS Word window flashing/poping up. I dont think I removed any critical lines in the script to cause this. Thanks for you help on this jhicks

User avatar
jhicks
Posts: 1789
Joined: Sun Jan 21, 2007 11:31 pm

How to suppress MS Word window in spell check scri

Post by jhicks »

Ok. If the script has to make changes, the user has to intervene and select the correction. When the file is saved, then Word does flash by briefly. I don't think there's any way around it. Even though the VBA code works in VBScript, there is obviously some quirk where Word needs to be displayed when closing the file. But I'm curious as to how you are going to use this. Spell check is done on what ever text is in the clipboard, but corrections are never saved anywhere. Only wanting to know if there are no changes required?

jvierra
Posts: 14543
Joined: Tue May 22, 2007 9:57 am
Contact:

How to suppress MS Word window in spell check scri

Post by jvierra »

Sorry. I don't have an example in VBS. I posted the link to the code example but it's in C#.
Basicall you hand a word to teh correcting method and it hands back a list of possible corrections that you can choose from. I would look it up in the SDK.

What you are tryig to do will work with the code you had but you will have to put up with the window flashing. That can't be stopped without doing the whole thing manyually.
You can also get custom controls that will let you do spell checking.

Locked