我有很长的条款清单。超过90%是拼写错误。其中大多数是两个中间没有空格的单词。我注意到MS Word,Excel,Office等非常擅长建议拼写正确。当我运行拼写检查程序时,我没有时间确认每一个建议的修正。有一些错误是可以的。
如何在不提示的情况下自动进行拼写检查,或者更确切地说“拼写正确”?我不介意使用除微软之外的其他工具,但它的拼写检查似乎相当不错。我尝试使用一些VBA代码与Excel一起使用,但我找不到任何能以编程方式向我显示主要建议的内容,以便我可以替换拼写错误的术语。
Sub spellcheck()
With Application.SpellingOptions
.SuggestMainOnly = True
.IgnoreCaps = True
.
End With
Cells.CheckSpelling
End Sub
感谢任何帮助。请理解自动纠正的危险。错误更正的影响微乎其微。
谢谢, 史蒂夫
答案 0 :(得分:4)
第三方拼写检查程序(例如aspell)可能会为您提供最快速度和最快速度。灵活性。但显然,你可以control the spell checker of Access,这可能是一种可能性。
鉴于您的特殊情况是由于两个单词之间缺少空格而导致错误,您可以使用Excel的拼写检查程序:
Sub test()
Dim str, correction As String
Dim i As Long, n As Long
With Application
For Each str In Array("pancake", "sausagebiscuit", "oatmeal", "largecoffee")
correction = str ' by default leave alone
If .CheckSpelling(str) Then
' already a word
Else
n = Len(str)
For i = 1 To n
If .CheckSpelling(Left$(str, i)) And .CheckSpelling(Right$(str, n - i)) Then
correction = Left$(str, i) & " " & Right$(str, n - i)
End If
Next
End If
Debug.Print str & " -> " & correction
Next
End With
End Sub
输出:
pancake -> pancake
sausagebiscuit -> sausage biscuit
oatmeal -> oatmeal
largecoffee -> large coffee
嗯,早餐......
答案 1 :(得分:1)
假设您在A列中有一个拼写错误的单词列表(从第1行开始)并在B列中进行了更正,您可以使用此宏将它们添加到Office的自动更正库中。这样,Excel将在输入单词后立即替换单词及其更正。
Sub subAddAutoCorrects() Dim rng As Range Set rng = Sheets("Sheet1").Range("A1") While rng "" Application.AutoCorrect.AddReplacement What:=rng.Value, Replacement:=rng.Offset(, 1).Value Set rng = rng.Offset(1) Wend End Sub
答案 2 :(得分:1)
已经有一年多了,但也许你仍然需要解决这个问题的方法 试试这个(以ms字为单位):
Sub use_suggestion()
Dim rng As Range
Dim i As Long
For i = 1 To ActiveDocument.Range.SpellingErrors.Count
Set rng = ActiveDocument.Range.SpellingErrors(i)
If rng.GetSpellingSuggestions.Count <> 0 Then
rng = rng.GetSpellingSuggestions.Item(1).Name & "ZXQ"
End If
Next i
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "ZXQ"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
注意:没有建议的拼写错误的单词不会改变。