Using script to spell check

  • Thread starter Thread starter **Developer**
  • Start date Start date
D

**Developer**

Below is my first script code.
I did it sometime ago and I believe I copied most of it from somewhere.
I would appreciate any suggested improvements.
The main reason for this post is that when I shutdown XP I'm notified
sometimes that Word is running.
I wonder it this code might be the culprit.

Thanks in advance


Option Explicit

Dim objWord, Word, WshShell, BtnCode, strSuggestion, lstSuggestions

Do While True

word = InputBox ("What word would you like to check?","Type the word to
check","")
if word = "" then WScript.Quit

Set objWord = CreateObject("Word.Application")

objWord.visible=False
objWord.Documents.Add.Content = word

if objWord.CheckSpelling(word) then
lstSuggestions = "Word is spelled OK."
else
lstSuggestions = ""
for each strSuggestion in objWord.GetSpellingSuggestions(word)
lstSuggestions = lstSuggestions & vbCrLf & strSuggestion
next
end if
Set WshShell = WScript.CreateObject("WScript.Shell")
BtnCode = WshShell.Popup(lstSuggestions, , "Spelling Suggestions
for """ & word & """. Click OK to Enter Another Word", 1 + 32)

Select Case BtnCode
case 2 WScript.Quit
case -1 WScript.Echo "Is there anybody out there?"
End Select

Loop
 
Office Space: Using the Spelling Checker in Microsoft Word:
http://www.microsoft.com/technet/scriptcenter/resources/officetips/aug05/tips0811.mspx

May be the objword.quit statement is the key.

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


Below is my first script code.
I did it sometime ago and I believe I copied most of it from somewhere.
I would appreciate any suggested improvements.
The main reason for this post is that when I shutdown XP I'm notified
sometimes that Word is running.
I wonder it this code might be the culprit.

Thanks in advance


Option Explicit

Dim objWord, Word, WshShell, BtnCode, strSuggestion, lstSuggestions

Do While True

word = InputBox ("What word would you like to check?","Type the word to
check","")
if word = "" then WScript.Quit

Set objWord = CreateObject("Word.Application")

objWord.visible=False
objWord.Documents.Add.Content = word

if objWord.CheckSpelling(word) then
lstSuggestions = "Word is spelled OK."
else
lstSuggestions = ""
for each strSuggestion in objWord.GetSpellingSuggestions(word)
lstSuggestions = lstSuggestions & vbCrLf & strSuggestion
next
end if
Set WshShell = WScript.CreateObject("WScript.Shell")
BtnCode = WshShell.Popup(lstSuggestions, , "Spelling Suggestions
for """ & word & """. Click OK to Enter Another Word", 1 + 32)

Select Case BtnCode
case 2 WScript.Quit
case -1 WScript.Echo "Is there anybody out there?"
End Select

Loop
 
I think objword.quit does shuts down Word.

But when that happens Word becomes visible and wants to know if I want to
save the document.

I've been looking for some docs on what commands are available to send Word
from the script.

Can't find any help. Did find info on how to write windows script, but not
about what Word exposes.

So I'm looking for help in two areas:

1) How to quit Word without it asking if I want to save the document.

2)How to find out what methods and properties Word exposes.


Thanks for any help
 
The Quit statement can accept additional parameters. Try this modifled code,
works perfectly here. winword.exe instance is closed automatically:

- - - - - - - - - -
Option Explicit
Dim objWord, Word, WshShell, BtnCode, strSuggestion, lstSuggestions
Const wdDoNotSaveChanges = 0

Do While True

word = InputBox ("What word would you like to check?","Type the word to
check","")
if word = "" then WScript.Quit

Set objWord = CreateObject("Word.Application")

objWord.visible=False
objWord.Documents.Add.Content = word

if objWord.CheckSpelling(word) then
lstSuggestions = "Word is spelled OK."
else
lstSuggestions = ""
for each strSuggestion in objWord.GetSpellingSuggestions(word)
lstSuggestions = lstSuggestions & vbCrLf & strSuggestion
next
end if
Set WshShell = WScript.CreateObject("WScript.Shell")
BtnCode = WshShell.Popup(lstSuggestions, , "Spelling Suggestions
for """ & word & """. Click OK to Enter Another Word", 1 + 32)

Select Case BtnCode
case 2
objWord.ActiveDocument.ActiveWindow.Close(wdDoNotSaveChanges)
objWord.Quit (wdDoNotSaveChanges)
Set objWord = Nothing
WScript.Quit

case -1 WScript.Echo "Is there anybody out there?"
End Select

Loop

- - - - - - - - - -

For your 2nd question:

Quit Method:
http://msdn.microsoft.com/library/d...en-us/vbawd11/html/womthClose1_HV03076767.asp

Close:
http://msdn.microsoft.com/library/d...ry/en-us/vbawd10/html/woproActiveDocument.asp

Microsoft Word Enumerated Constants: *** Refer "wdDoNotSaveChanges" in this
page.
http://msdn.microsoft.com/library/d...us/vbawd11/html/wohowConstants_HV01049731.asp

Word Application Object Methods:
http://msdn.microsoft.com/library/d...-us/dv_wrcore/html/wrgrfapplicationobject.asp

Word Application Object Properties:
http://msdn.microsoft.com/library/d...-us/dv_wrcore/html/wrgrfapplicationobject.asp

Office Space: Using the Spelling Checker in Microsoft Word:
http://www.microsoft.com/technet/scriptcenter/resources/officetips/aug05/tips0811.mspx
*** The above method does not show the "save as" prompt, and it should be
run using cscript.exe

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


I think objword.quit does shuts down Word.

But when that happens Word becomes visible and wants to know if I want to
save the document.

I've been looking for some docs on what commands are available to send Word
from the script.

Can't find any help. Did find info on how to write windows script, but not
about what Word exposes.

So I'm looking for help in two areas:

1) How to quit Word without it asking if I want to save the document.

2)How to find out what methods and properties Word exposes.


Thanks for any help


Ramesh said:
Office Space: Using the Spelling Checker in Microsoft Word:
http://www.microsoft.com/technet/scriptcenter/resources/officetips/aug05/tips0811.mspx

May be the objword.quit statement is the key.

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


Below is my first script code.
I did it sometime ago and I believe I copied most of it from somewhere.
I would appreciate any suggested improvements.
The main reason for this post is that when I shutdown XP I'm notified
sometimes that Word is running.
I wonder it this code might be the culprit.

Thanks in advance
 
Small correction
-----------------

Remove this line alone, and all should work fine:

objWord.ActiveDocument.ActiveWindow.Close(wdDoNotSaveChanges)

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


The Quit statement can accept additional parameters. Try this modifled code,
works perfectly here. winword.exe instance is closed automatically:

- - - - - - - - - -
Option Explicit
Dim objWord, Word, WshShell, BtnCode, strSuggestion, lstSuggestions
Const wdDoNotSaveChanges = 0

Do While True

word = InputBox ("What word would you like to check?","Type the word to
check","")
if word = "" then WScript.Quit

Set objWord = CreateObject("Word.Application")

objWord.visible=False
objWord.Documents.Add.Content = word

if objWord.CheckSpelling(word) then
lstSuggestions = "Word is spelled OK."
else
lstSuggestions = ""
for each strSuggestion in objWord.GetSpellingSuggestions(word)
lstSuggestions = lstSuggestions & vbCrLf & strSuggestion
next
end if
Set WshShell = WScript.CreateObject("WScript.Shell")
BtnCode = WshShell.Popup(lstSuggestions, , "Spelling Suggestions
for """ & word & """. Click OK to Enter Another Word", 1 + 32)

Select Case BtnCode
case 2
objWord.ActiveDocument.ActiveWindow.Close(wdDoNotSaveChanges)
objWord.Quit (wdDoNotSaveChanges)
Set objWord = Nothing
WScript.Quit

case -1 WScript.Echo "Is there anybody out there?"
End Select

Loop

- - - - - - - - - -

For your 2nd question:

Quit Method:
http://msdn.microsoft.com/library/d...en-us/vbawd11/html/womthClose1_HV03076767.asp

Close:
http://msdn.microsoft.com/library/d...ry/en-us/vbawd10/html/woproActiveDocument.asp

Microsoft Word Enumerated Constants: *** Refer "wdDoNotSaveChanges" in this
page.
http://msdn.microsoft.com/library/d...us/vbawd11/html/wohowConstants_HV01049731.asp

Word Application Object Methods:
http://msdn.microsoft.com/library/d...-us/dv_wrcore/html/wrgrfapplicationobject.asp

Word Application Object Properties:
http://msdn.microsoft.com/library/d...-us/dv_wrcore/html/wrgrfapplicationobject.asp

Office Space: Using the Spelling Checker in Microsoft Word:
http://www.microsoft.com/technet/scriptcenter/resources/officetips/aug05/tips0811.mspx
*** The above method does not show the "save as" prompt, and it should be
run using cscript.exe

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


I think objword.quit does shuts down Word.

But when that happens Word becomes visible and wants to know if I want to
save the document.

I've been looking for some docs on what commands are available to send Word
from the script.

Can't find any help. Did find info on how to write windows script, but not
about what Word exposes.

So I'm looking for help in two areas:

1) How to quit Word without it asking if I want to save the document.

2)How to find out what methods and properties Word exposes.


Thanks for any help


Ramesh said:
Office Space: Using the Spelling Checker in Microsoft Word:
http://www.microsoft.com/technet/scriptcenter/resources/officetips/aug05/tips0811.mspx

May be the objword.quit statement is the key.

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


Below is my first script code.
I did it sometime ago and I believe I copied most of it from somewhere.
I would appreciate any suggested improvements.
The main reason for this post is that when I shutdown XP I'm notified
sometimes that Word is running.
I wonder it this code might be the culprit.

Thanks in advance
 
Works great!

Inside the loop, in two places I have a CreatObject

The first one can be move in front of the loop (and as you pointed out it
can be set to Nothing). Is that a good thing to do?
Should I do something with the other object ("WScript.Shell")?

Thanks

Ramesh said:
Small correction
-----------------

Remove this line alone, and all should work fine:

objWord.ActiveDocument.ActiveWindow.Close(wdDoNotSaveChanges)

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


The Quit statement can accept additional parameters. Try this modifled
code,
works perfectly here. winword.exe instance is closed automatically:

- - - - - - - - - -
Option Explicit
Dim objWord, Word, WshShell, BtnCode, strSuggestion, lstSuggestions
Const wdDoNotSaveChanges = 0

Do While True

word = InputBox ("What word would you like to check?","Type the word to
check","")
if word = "" then WScript.Quit

Set objWord = CreateObject("Word.Application")

objWord.visible=False
objWord.Documents.Add.Content = word

if objWord.CheckSpelling(word) then
lstSuggestions = "Word is spelled OK."
else
lstSuggestions = ""
for each strSuggestion in objWord.GetSpellingSuggestions(word)
lstSuggestions = lstSuggestions & vbCrLf & strSuggestion
next
end if
Set WshShell = WScript.CreateObject("WScript.Shell")
BtnCode = WshShell.Popup(lstSuggestions, , "Spelling Suggestions
for """ & word & """. Click OK to Enter Another Word", 1 + 32)

Select Case BtnCode
case 2
objWord.ActiveDocument.ActiveWindow.Close(wdDoNotSaveChanges)
objWord.Quit (wdDoNotSaveChanges)
Set objWord = Nothing
WScript.Quit

case -1 WScript.Echo "Is there anybody out there?"
End Select

Loop

- - - - - - - - - -

For your 2nd question:

Quit Method:
http://msdn.microsoft.com/library/d...en-us/vbawd11/html/womthClose1_HV03076767.asp

Close:
http://msdn.microsoft.com/library/d...ry/en-us/vbawd10/html/woproActiveDocument.asp

Microsoft Word Enumerated Constants: *** Refer "wdDoNotSaveChanges" in
this
page.
http://msdn.microsoft.com/library/d...us/vbawd11/html/wohowConstants_HV01049731.asp

Word Application Object Methods:
http://msdn.microsoft.com/library/d...-us/dv_wrcore/html/wrgrfapplicationobject.asp

Word Application Object Properties:
http://msdn.microsoft.com/library/d...-us/dv_wrcore/html/wrgrfapplicationobject.asp

Office Space: Using the Spelling Checker in Microsoft Word:
http://www.microsoft.com/technet/scriptcenter/resources/officetips/aug05/tips0811.mspx
*** The above method does not show the "save as" prompt, and it should be
run using cscript.exe

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


I think objword.quit does shuts down Word.

But when that happens Word becomes visible and wants to know if I want to
save the document.

I've been looking for some docs on what commands are available to send
Word
from the script.

Can't find any help. Did find info on how to write windows script, but not
about what Word exposes.

So I'm looking for help in two areas:

1) How to quit Word without it asking if I want to save the document.

2)How to find out what methods and properties Word exposes.


Thanks for any help


Ramesh said:
Office Space: Using the Spelling Checker in Microsoft Word:
http://www.microsoft.com/technet/scriptcenter/resources/officetips/aug05/tips0811.mspx

May be the objword.quit statement is the key.

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


Below is my first script code.
I did it sometime ago and I believe I copied most of it from somewhere.
I would appreciate any suggested improvements.
The main reason for this post is that when I shutdown XP I'm notified
sometimes that Word is running.
I wonder it this code might be the culprit.

Thanks in advance
 
slight change

Works great!

Inside the loop, in two places I have a CreatObject

The first one can be move in front of the loop (and as you pointed out it
can be set to Nothing). Is moving it a good thing to do?
Should I do something with the other object ("WScript.Shell")?

Thanks

Ramesh said:
Small correction
-----------------

Remove this line alone, and all should work fine:

objWord.ActiveDocument.ActiveWindow.Close(wdDoNotSaveChanges)

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


The Quit statement can accept additional parameters. Try this modifled
code,
works perfectly here. winword.exe instance is closed automatically:

- - - - - - - - - -
Option Explicit
Dim objWord, Word, WshShell, BtnCode, strSuggestion, lstSuggestions
Const wdDoNotSaveChanges = 0

Do While True

word = InputBox ("What word would you like to check?","Type the word
to
check","")
if word = "" then WScript.Quit

Set objWord = CreateObject("Word.Application")

objWord.visible=False
objWord.Documents.Add.Content = word

if objWord.CheckSpelling(word) then
lstSuggestions = "Word is spelled OK."
else
lstSuggestions = ""
for each strSuggestion in objWord.GetSpellingSuggestions(word)
lstSuggestions = lstSuggestions & vbCrLf & strSuggestion
next
end if
Set WshShell = WScript.CreateObject("WScript.Shell")
BtnCode = WshShell.Popup(lstSuggestions, , "Spelling Suggestions
for """ & word & """. Click OK to Enter Another Word", 1 + 32)

Select Case BtnCode
case 2

objWord.ActiveDocument.ActiveWindow.Close(wdDoNotSaveChanges)
objWord.Quit (wdDoNotSaveChanges)
Set objWord = Nothing
WScript.Quit

case -1 WScript.Echo "Is there anybody out there?"
End Select

Loop

- - - - - - - - - -

For your 2nd question:

Quit Method:
http://msdn.microsoft.com/library/d...en-us/vbawd11/html/womthClose1_HV03076767.asp

Close:
http://msdn.microsoft.com/library/d...ry/en-us/vbawd10/html/woproActiveDocument.asp

Microsoft Word Enumerated Constants: *** Refer "wdDoNotSaveChanges" in
this
page.
http://msdn.microsoft.com/library/d...us/vbawd11/html/wohowConstants_HV01049731.asp

Word Application Object Methods:
http://msdn.microsoft.com/library/d...-us/dv_wrcore/html/wrgrfapplicationobject.asp

Word Application Object Properties:
http://msdn.microsoft.com/library/d...-us/dv_wrcore/html/wrgrfapplicationobject.asp

Office Space: Using the Spelling Checker in Microsoft Word:
http://www.microsoft.com/technet/scriptcenter/resources/officetips/aug05/tips0811.mspx
*** The above method does not show the "save as" prompt, and it should be
run using cscript.exe

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


I think objword.quit does shuts down Word.

But when that happens Word becomes visible and wants to know if I want to
save the document.

I've been looking for some docs on what commands are available to send
Word
from the script.

Can't find any help. Did find info on how to write windows script, but
not
about what Word exposes.

So I'm looking for help in two areas:

1) How to quit Word without it asking if I want to save the document.

2)How to find out what methods and properties Word exposes.


Thanks for any help


Ramesh said:
Office Space: Using the Spelling Checker in Microsoft Word:
http://www.microsoft.com/technet/scriptcenter/resources/officetips/aug05/tips0811.mspx

May be the objword.quit statement is the key.

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


Below is my first script code.
I did it sometime ago and I believe I copied most of it from somewhere.
I would appreciate any suggested improvements.
The main reason for this post is that when I shutdown XP I'm notified
sometimes that Word is running.
I wonder it this code might be the culprit.

Thanks in advance
 
It's better to move CreateObject outside the loop, and move it to the top.

--
Regards,

Ramesh Srinivasan, Microsoft MVP [Windows XP Shell/User]
Windows® XP Troubleshooting http://www.winhelponline.com


Works great!

Inside the loop, in two places I have a CreatObject

The first one can be move in front of the loop (and as you pointed out it
can be set to Nothing). Is that a good thing to do?
Should I do something with the other object ("WScript.Shell")?

Thanks
 
Back
Top