Solved

batch spell check correction

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now