Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Can we get the spelling mistake words separately from the word file

Hi All,
Can we get the spelling mistake words separately from the word file

I have 10 word files and each has 80,000+ words

Can anyone hep with a script that can check each file and copy the spell mistake word and if possible the grammar mistake words to a separate file?

Like check where words re in red and green and copy?

thanks
Avatar of irudyk
irudyk
Flag of Canada image

Try the following code which will first output all of the spelling errors and then all of the grammatical errors for each document.  It assumes that all of the files to check are in the same folder (the path to which you will need to modify in Line 12 of the code.
Sub GetSpellingGrammarErrors()

'if all of the documents are in the same folder
Dim strDocFile As String
Dim strDocPath As String
Dim e As Long
Dim eDoc As Document
Dim cDoc As Document

Set eDoc = Documents.Add(DocumentType:=wdNewBlankDocument)

strDocPath = "C:\Path\"   'enter the path to your file here
strDocFile = Dir(strDocPath & "*.doc*")

While strDocFile <> ""
    
    Set cDoc = Documents.Open(strDocPath & strDocFile)
    If cDoc.SpellingErrors.Count > 0 Or cDoc.GrammaticalErrors.Count > 0 Then
        For e = 1 To cDoc.SpellingErrors.Count
            eDoc.ActiveWindow.Selection.TypeText cDoc.SpellingErrors(e).Text & vbCr
       Next e
        For e = 1 To cDoc.GrammaticalErrors.Count
            eDoc.ActiveWindow.Selection.TypeText cDoc.GrammaticalErrors(e).Text & vbCr
        Next e
    End If
    cDoc.Close wdDoNotSaveChanges
    strDocFile = Dir

Wend

Set cDoc = Nothing
Set eDoc = Nothing

End Sub

Open in new window

Avatar of bsharath

ASKER

Thanks works fine

Can i get 2 files one is spellings and another is grammar issues

Also can it refer a dictionary to skip words that i added?

As the output of 1,20,000 words were 33,000 mistakes

if i can add the dictionary words i have so it can skip them while scanning
Okay try the following code for 2 seperate files:
Sub GetSpellingGrammarErrors()

'if all of the documents are in the same folder
Dim strDocFile As String
Dim strDocPath As String
Dim e As Long
Dim eDoc As Document
Dim gDoc As Document
Dim cDoc As Document

Set eDoc = Documents.Add(DocumentType:=wdNewBlankDocument)
Set gDoc = Documents.Add(DocumentType:=wdNewBlankDocument)

strDocPath = "C:\Path\"   'enter the path to your file here
strDocFile = Dir(strDocPath & "*.doc*")

While strDocFile <> ""
    
    Set cDoc = Documents.Open(strDocPath & strDocFile)
    If cDoc.SpellingErrors.Count > 0 Or cDoc.GrammaticalErrors.Count > 0 Then
        For e = 1 To cDoc.SpellingErrors.Count
            eDoc.ActiveWindow.Selection.TypeText cDoc.SpellingErrors(e).Text & vbCr
       Next e
        For e = 1 To cDoc.GrammaticalErrors.Count
            gDoc.ActiveWindow.Selection.TypeText cDoc.GrammaticalErrors(e).Text & vbCr
        Next e
    End If
    cDoc.Close wdDoNotSaveChanges
    strDocFile = Dir

Wend

Set cDoc = Nothing
Set eDoc = Nothing
Set eDoc = Nothing

End Sub

Open in new window


I'm not clear what you are referring to regarding a "dictionary to skip words that I added". I mean if those words are added to the dictionary within Word, they should already be skipped during a spell check.
Thanks
1. Is there a way that we can backup a custom dictionary?

2. How can we add a custom dictionary

As these files are too many

I have few 1,000 words in my excel that i need to add to word dictionary and then give this dictionary to 5+ people who will check these files

So these words are not shows as spelling issues to them?
What version of Office are you using?
What you can try is the following:
Open your Excel file, select and copy the list of words
Open Notepad and paste the text you copied from Excel
Save the Notepad file as Custom2.DIC
  make sure the file type is set to All types (*.*) otherwise
  the file will be saved as Custon2.DIC.txt
You can distribute the Custom2.DIC file to the other users who can save the file in their My Documents folder.

Now, assuming that you are using Word 2010, you and the other users you sent the Custom2.DIC file to should do the following in order to add the new custom dictionary for Word to reference:
Select File | Options | Proofing
Click the Custom Dictionaries... button
Click the Add... button
Search for and select the Custom2.DIC file and click Open
Click OK

Doing the above should work and prevent those words from being added as spelling errors.
Can you mention the method for office 2003 or 2007 please...
Also how can we backup and view the current default dictionary
ASKER CERTIFIED SOLUTION
Avatar of irudyk
irudyk
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry to get back on this i get this error

---------------------------
Windows Script Host
---------------------------
Script:      D:\Path\Find spelling and grammar.vbs
Line:      4
Char:      16
Error:      Expected end of statement
Code:      800A0401
Source:       Microsoft VBScript compilation error

---------------------------
OK  
---------------------------