Spellchecking

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
OlgaFB
Pro Scripter
Posts: 58
Joined: Mon Nov 01, 2004 3:04 pm
Contact:

Spellchecking

Post by OlgaFB » Wed Aug 23, 2006 2:33 pm

Hi Marcus,

I saw an example of spellchecking function in VB Tutorial and tried it in a Macro Scheduler script.

Here's how it looks:

Code: Select all

VBSTART
Function SP()
Dim Word, Doc, Uncorrected, Corrected
Const wdDialogToolsSpellingAndGrammar = 828
Const wdDoNotSaveChanges = 0

Uncorrected = "In life, yotu can only ever be sycared, when you beljieve in limits." 
Set Word = CreateObject("Word.Application")
'Set Doc = Word.Documents.Add( "", False) 
Set Doc = Word.Documents.Add
Word.Selection.Text = Uncorrected
Word.Dialogs(wdDialogToolsSpellingAndGrammar).Show

If Len(Word.Selection.Text) <> 1 Then 
Corrected = Word.Selection.Text
Else
   Corrected = Uncorrected
End If
'MsgBox Corrected
Word.Visible = False
Doc.Close wdDoNotSaveChanges
'Word.Dialogs(wdDialogToolsSpellingAndGrammar).Close wdDoNotSaveChanges
Word.Quit
'MsgBox "finished"
SP = Corrected
End Function
VBEND

VBEval>SP(),result
'messagemodal>result
The problem is, that each such function, as shows in Task Manager Processes tab, leaves a WINWORD.EXE running.

I can make Word a global variable, but still, every time the script runs, it wil create yet another instance. When the script quits, the processes don't terminate, either.

Is there any way to handle it? To know, may be, which exactly processes were initiated by the script?

Because it's probably easy to just go and kill all WINWORD processes. :) But if the user has at this time some Word document open, he may not like it... :)

Could you please suggest a solution?

Thank you,
Olga.

If the phrase sounded interesting to someone, here it is:

"In life, you can only ever be scared, when you believe in limits.
You can only ever feel lonely, when you stop doing things.
You can only ever become bored, when you no longer follow your heart.
And you can only ever get overwhelmed, when you think the illusions are real.
Whew! Who knew it could be so easy to get back on track?
The Universe"
-- from Notes from the Universe, by Mike Dooley, http://tut.com

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Aug 23, 2006 2:38 pm

this line ...

Set Word = CreateObject("Word.Application")

... creates an instance of winword.exe

At the end of the function you should have a ...

Word.quit

... that will exit the new word instance. So there should no longer be an instance of winword.exe running.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

OlgaFB
Pro Scripter
Posts: 58
Joined: Mon Nov 01, 2004 3:04 pm
Contact:

Post by OlgaFB » Wed Aug 23, 2006 2:50 pm

Marcus, but I do have such a line at the end of the function! And yet still, when I run the script, a new instance of WINWORD is shown as an added running process, it doesn't go away.

Thank you,
Olga.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Aug 23, 2006 2:53 pm

Without seeing the full script I can't say why that would be. Something would appear to be preventing quit to work. This example, which does nothing does not leave winword.exe running:

Code: Select all

VBSTART
Set Word = CreateObject("Word.Application")
Word.visible = true
Word.quit
VBEND
You *might* get some clues if you make Word visible with:

Word.visible = true

Then you might be able to see something that it is doing which is preventing quit from working.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
pgriffin
Automation Wizard
Posts: 460
Joined: Wed Apr 06, 2005 5:56 pm
Location: US and Europe

Post by pgriffin » Wed Aug 23, 2006 3:16 pm

I have a colleague with this same problem. He is writing in JavaScript and having some issues with multiple instances of WINWORD.

My question is does QUIT cause all instances to quit or only the one created by this function?

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Aug 23, 2006 3:24 pm

Word.quit calls the quit method of the word object. The word object was created with the set word = createobject.... line. So in this case it only affects the one instance - the object created at the start of the function. It won't affect any existing instances.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

OlgaFB
Pro Scripter
Posts: 58
Joined: Mon Nov 01, 2004 3:04 pm
Contact:

Post by OlgaFB » Wed Aug 23, 2006 3:36 pm

Marcus,

I'm calling all the Quits needed, and so far I couldn't find any solution to this regarding this Word object.

So could you please look into the possibilities with the processes? Is there a way to know which WINWORD processes were initiated by Macro Scheduler VBScript? Is there a possibility to terminate them?

Thank you very much,
Olga.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Aug 23, 2006 3:41 pm

So could you please look into the possibilities with the processes? Is there a way to know which WINWORD processes were initiated by Macro Scheduler VBScript? Is there a possibility to terminate them?
Not that I'm aware of. You can terminate processes (see: http://www.mjtnet.com/forum/viewtopic.php?t=1779).

You can also get the process ID with GetWindowProcess which can take a window title or handle. So if you have some way of getting the window title or handle of the new Winword window you could get the process ID and then kill it. Thinking out loud here - if you initially make the word object visible you could then get it's handle with GetActiveWindow, or GetWindowHandle and in turn get it's PID.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?


Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts