更新後的腳本我正在使用該原因導致LOCKUP ...我嘗試用(Replace:= wdReplaceAll)替換(Replace:= wdReplaceOne),但仍然沒有運氣:如何設置某種排序的VBA查找/替換腳本
Option Explicit
'Dim strMacroName As String
Dim spellingcorrectionsrep As Long
Public Sub SpellingReview()
Dim oShell, MyDocuments
「的聲明文件路徑MyDocs: 設置oShell =的CreateObject( 「Wscript.Shell」) 我的文檔= oShell.SpecialFolders( 「我的文檔」) 設置oShell =無
' 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
是你的字典一個固定大小的,具有固定值(所以你可以硬編碼的每個單詞),或者從一些其他地方拍攝? – NickSlash