更新的脚本我正在使用导致锁定...我尝试用 (Replace:=wdReplaceAll) 替换 (Replace:=wdReplaceOne),但仍然没有这样的运气:
Option Explicit
'Dim strMacroName As String
Dim spellingcorrectionsrep As Long
Public Sub SpellingReview()
Dim oShell, MyDocuments
'声明 MyDocs 文件路径: Set oShell = CreateObject("Wscript.Shell") MyDocuments = oShell.SpecialFolders("MyDocuments") Set oShell = Nothing
' Set values for variables of the actual word to find/replace
spellingsuggestionsrep = 0
spellingcorrectionsrep = 0
' Replacements
SpellingCorrections "dog", "dog (will be changed to cat)", False, True
' END SEARCHING DOCUMENT AND DISPLAY MESSAGE
MsgBox spellingcorrectionsrep
'strMacroName = "Spelling Review"
'Call LogMacroUsage(strMacroName)
End Sub
Sub SpellingCorrections(sInput As String, sReplace As String, MC As Boolean, MW As Boolean)
' Set Selection Search Criteria
Selection.HomeKey Unit:=wdStory
With Selection
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Highlight = True
.Text = sInput
.Replacement.Text = sReplace
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchWildcards = False
.MatchCase = MC
.MatchWholeWord = MW
End With
Do While .Find.Execute = True
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
If .Find.Execute(Replace:=wdReplaceOne) = True Then
spellingcorrectionsrep = spellingcorrectionsrep + 1
End If
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
Loop
End With
End Sub