Solved

batch spell check correction

Posted on 2004-09-03
3
712 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
  • 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.

733 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