Solved

batch spell check correction

Posted on 2004-09-03
3
714 Views
Last Modified: 2008-01-09
I need to write a Macro that will do the following:

1. Take a specified file whose name is the format <base>.in.txt, e.g. "text.in.txt"
2. Spell check it
3. Replace each misspelled word with the top correction suggested by the spell checker. If there are no suggestions, leave word as is.
4. Save result into the file <base>.out.txt, i.e. "text.out.txt"
0
Comment
Question by:ilyaz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
Kelly_in_Los_Angeles earned 200 total points
ID: 11977901
Hi ilyaz,

Will the following work for you?

I'm pretty sure you have an understanding of the code, so I will assume that my code commentary within the macro will serve as a sufficient explanation.

On the other hand, if you have questions about any of it, then of course you are more than welcome to ask me right away and I will answer tout de suite!

Sub Auto_Spell_and_Rename_and_Save()

Dim InWhatFolder As String
Dim FileNameEnding As String
Dim SaveNameEnding As String
Dim mySearchString As String
Dim myFileName As String
Dim myDoc As Document
Dim SpellSuggs As SpellingSuggestions
Dim mySaveName As String

'******** YOU MUST PERSONALIZE THE FOLLOWING THREE STRING VALUES ****
InWhatFolder = "C:\My txt files\"
FileNameEnding = ".in.txt"
SaveNameEnding = ".out.txt"

mySearchString = InWhatFolder & "*" & FileNameEnding

myFileName = Dir(mySearchString)

If myFileName = "" Then
MsgBox "No files match the criteria: " & mySearchString
End
End If
'If no file matches the file address created by combining InWhatFolder
'with FileNameEnding, then this macro will end RIGHT HERE.

'If we get this far, then at least one file was found
Do

'open the file we found.
Set myDoc = Documents.Open(InWhatFolder & myFileName)

'********* START THE SPELLING CHECK LOOP ********************
    Do While myDoc.SpellingErrors.Count >= 1
   
    Set SpellSuggs = GetSpellingSuggestions(myDoc.SpellingErrors(1).Text)
   
    If SpellSuggs.Count >= 1 Then
        myDoc.SpellingErrors(1).Text = SpellSuggs(1)
    Else
        myDoc.SpellingErrors(1).NoProofing = True
    End If
   
    Loop
'********* END THE SPELLING CHECK LOOP ***********************

mySaveName = Left(myFileName, Len(myFileName) - Len(FileNameEnding)) _
             & SaveNameEnding

'************ SAVE WITH A NEW NAME AND CLOSE THE DOCUMENT ************
myDoc.SaveAs InWhatFolder & mySaveName, wdFormatText
myDoc.Close

Set myDoc = Nothing

myFileName = Dir()

'Loop to the next file we find, unless none is found
Loop While myFileName <> ""

End Sub
0
 
LVL 1

Expert Comment

by:Kelly_in_Los_Angeles
ID: 11980442
I'm going out of town for the weekend, so if anyone has any questions I will answer them on Monday.  Sorry if that inconvenciences anyone!  (although I have a feeling that everyone else is gone for the weekend too)
0
 
LVL 22

Expert Comment

by:Dreamboat
ID: 11987477
Not me!  :(
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is often necessary in this forum and others to illustrate Word fields as text with the field delimiters replaced with the curly brackets that the delimiters resemble when field codes are being displayed on the document. This means that the text c…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question