Jump to content
Sign in to follow this  
Pakku

SpellCheck using Microsoft Word

Recommended Posts

Pakku

Hi all,

I wondered if I could use the Microsoft Word API to check if there are spell errors in my string, and if possible in a language of my choice.

After a week reseach (nobody ever did it the right way) i came up with the follow

Func _SpellCheck($String,$Language)
    
    ;For LanguageID use:
    ;http://www.microsoft.com/globaldev/reference/lcid-all.mspx
    
    $WordApp = ObjCreate("Word.Application")
    $rngRange = ObjCreate("Word.Range")
    $WordApp.Documents.Add()
    $rngRange = $WordApp.Activedocument.Range
    $rngRange.LanguageID = $Language
    $rngRange.InsertAfter($String)
    $SpellCollection = $rngRange.SpellingErrors
    If $SpellCollection.Count > 0 Then
        Return 0
    Else
        Return 1
    EndIf
    $WordApp.Quit(False)
EndFunc
oÝ÷ ØZ+¶jx.j붢YhÂ)àÁæì×®®oÝ÷ Ù*"q©º"¶ ­©¦z·!yÉ­«­¢+Ø)Õ¹}
¡­ÉµµÈ ÀÌØíMÑÉ¥¹°ÀÌØí1¹Õ¤($($í½È1¹Õ%ÕÍè($í¡ÑÑÀè¼½ÝÝܹµ¥É½Í½Ð¹½´½±½±Ø½Éɹ½±¥µ±°¹µÍÁà($($ÀÌØí]½ÉÁÀô=©
ÉÑ ÅÕ½Ðí]½É¹ÁÁ±¥Ñ¥½¸ÅÕ½Ðì¤($ÀÌØíɹI¹ô=©
ÉÑ ÅÕ½Ðí]½É¹I¹ÅÕ½Ðì¤($ÀÌØí]½ÉÁÀ¹½Õµ¹Ñ̹ ¤($ÀÌØíɹI¹ôÀÌØí]½ÉÁÀ¹Ñ¥Ù½Õµ¹Ð¹I¹($ÀÌØíɹI¹¹1¹Õ%ôÀÌØí1¹Õ($ÀÌØíɹI¹¹%¹ÍÉÑÑÈ ÀÌØíMÑÉ¥¹¤($ÀÌØíɵµÉ
½±±Ñ¥½¸ôÀÌØíɹI¹¹ÉµµÑ¥±ÉɽÉÌ(%ÀÌØíɵµÉ
½±±Ñ¥½¸¹
½Õ¹ÐÐìÀQ¡¸(IÑÕɸÀ(±Í(IÑÕɸÄ(¹%($ÀÌØí]½ÉÁÀ¹EեС±Í¤)¹Õ¹oÝ÷ Ù'iº/yú+¶¥jx.j¬zÛbéZ²Ú'xZ¾}ý¶×¬µçrzÖî¶+l¥w
+,²&åzÚ%zÚh¦êZv&¥¢"µÈç$²Ø^¶¦ªè®Ø^²¥)ànëm«b²}ý·Z´×ÊjwhÖòi×bh®
Úf«jëh×6
$GrammarCollection.CheckGrammar

Have a nice day and feedback is more than welcome!

Share this post


Link to post
Share on other sites
jvanegmond

You are definitely on to something. This returns whether it is right or wrong, but what would be great if you could get it to return possible corrections!

Share this post


Link to post
Share on other sites
GEOSoft

Looks familiar from way back when before any com was available :)

http://www.autoitscript.com/forum/index.ph...ost&p=10067

I still have one that I think you wrote and it comes in handy every now and then. It (IIRC) checks the selected text and then either puts it on the clipboard or shoots it into the doc. I might have added the shoot feature myself. I don't remember now. I started writing one that would check an entire document and check against a Scrabble word list but it was horrendously slow so I mothballed it.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
MrCreatoR

Hi all,

I have tried to make this function work without create temp vbs file (like here), but i have one problem:

_SpellCheckProc("1033")

Func _SpellCheckProc($Language)
    $Word = ObjCreate("word.Application")
    $Word.WindowState = 2
    $Word.Visible = True
    $Doc = $Word.Documents.Add("", "", 1, True)
    $Word.Selection.Paste
    If Not @error Then
        $Word.Selection.LanguageID = $Language
        $Doc.CheckGrammar
        $Word.Selection.WholeStory
        $Word.Selection.Copy
    EndIf
    $Doc.Close = False
    $Word.Application.Quit True
EndFuncoÝ÷ ضØb±ê뢺®¢×êު笵çZrب­Øb²ãyËajÇÚWÓ~¡

But the problem the same...

This work fine if i use the same code in vbs file (or create it from my script), but it wont work from the script, why? hot to make this work?

EDIT:

This work now (the second example), i forgot about the cariage returns and line feads (@CRLF) :)

Thanks to all.

Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
MHz

I get this error:

Skipped parameters in VBS are replaced with the Default keyword in AutoIt.

And also i tried like this (call vbs code):

I see no CRLFs used so it is one big line.

:)

Share this post


Link to post
Share on other sites
MrCreatoR

MHz

Skipped parameters in VBS are replaced with the Default keyword in AutoIt.

But how to use this method in autoIt? maby i need to set those parameters as something else?

I see no CRLFs used so it is one big line.

Yes, thanks, i realized this before i see your post, realy :"> - and edit it just 7 minutes after you posted :), the page probably was not updated (i am using Opera browser).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
big_daddy

I made a spell check GUI that uses Word's COM functionality.

Custom Spell Checker

Share this post


Link to post
Share on other sites
Pakku

I made a spell check GUI that uses Word's COM functionality.

Custom Spell Checker

Nice one!

Share this post


Link to post
Share on other sites
MHz

But how to use this method in autoIt? maby i need to set those parameters as something else?

VBS skips parameters like below

Set Doc = Word.Documents.Add( , , 1, True)

AutoIt does not allow skipped/empty parameters as such so you use the Default keyword

$Doc = $Word.Documents.Add(Default, Default, 1, True)

You were using "" instead which is different to using Default.

:)

Share this post


Link to post
Share on other sites
MrCreatoR

AutoIt does not allow skipped/empty parameters as such so you use the Default keyword

Thanks a lot...

But now i get the error when it's trying (not) to close the window:

$Doc.Close = False

The requested action with this object has failed.:

$Doc.Close = False

$Doc.Close = False ^ ERROR

When i write this line like this:

$Doc.Close (False)

It's ok, there is no error, but the window of word is not closing untill i finish the spelling corrections :rolleyes: - how am i do that the window will not been shown at all?


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
big_daddy

@MsCreatoR - Did you ever think to use the built-in MS Word Functions?

Share this post


Link to post
Share on other sites
MrCreatoR

big_daddy

Did you ever think to use the built-in MS Word Functions?

Hmm... I don't sure if i understand what you mean? where i find those functions? :rolleyes:


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites
i542

Hi all,

I wondered if I could use the Microsoft Word API to check if there are spell errors in my string, and if possible in a language of my choice.

(...)

It is nice. As far as I can see because I don't have Word. I use OpenOffice.org instead.

Looks familiar from way back when before any com was available :rolleyes:

http://www.autoitscript.com/forum/index.ph...ost&p=10067

ouch, JdeB gived you a fire punch, arjan!

I can do signature me.

Share this post


Link to post
Share on other sites
Pakku

It is nice. As far as I can see because I don't have Word. I use OpenOffice.org instead.

ouch, JdeB gived you a fire punch, arjan!

hahaha, i know he means well (well i hope :rolleyes: )

Edited by Pakku

Share this post


Link to post
Share on other sites
Jos

hahaha, i know he means well (well i hope :rolleyes: )

Arjan

Don't understand where I987 is coming from but just get used to him not making any sense what so ever .....

:rambo:


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
big_daddy

big_daddy

Hmm... I don't sure if i understand what you mean? where i find those functions? :rolleyes:

The help file...

_WordCreate()

_WordDocGetCollection()

etc...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×