Solved

batch spell check correction

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
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…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

919 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

14 Experts available now in Live!

Get 1:1 Help Now