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
Solved

batch spell check correction

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

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
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…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
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.

828 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