【发布时间】:2016-02-23 20:49:57
【问题描述】:
我正在尝试全部替换,然后只锁定替换单词,而不是全部。
例如:
句子:“我要去市场” 查找:“市场” 替换:“学校”
然后,锁定单词“学校”。
Dim Datas(500) As String
Dim CariKata As String
Datas(1) = "Shop"
Datas(2) = "Office"
Selection.WholeStory
Selection.Editors.Add wdEditorEveryone
For h = 1 To 2
CariKata = Datas(h)
For i = 1 To CountWordPhrase(CariKata)
Selection.find.ClearFormatting
Selection.find.Replacement.ClearFormatting
With Selection.find
.Text = CariKata
.Replacement.Text = "school"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.MatchPhrase = True
End With
Selection.find.Execute
Selection.Editors(wdEditorEveryone).Delete
Next i
ActiveDocument.Protect Password:="123", NoReset:=False, Type:= _
wdAllowOnlyReading, UseIRM:=False, EnforceStyleLock:=False
Next h
End Sub
Function CountWordPhrase(ByVal KataDicari As String)
Dim Response, ExitResponse
Dim y As Integer
On Error Resume Next
With ActiveDocument.Content.find
Do While .Execute(FindText:=KataDicari, Forward:=True, Format:=True, _
MatchWholeWord:=True) = True
' Display message in Word's Status Bar.
StatusBar = "Word is counting the occurrences of the text " & _
Chr$(34) & x & Chr$(34) & "."
y = y + 1
Loop
End With
结束函数
此脚本成功查找并锁定,但无法查找、替换和锁定。
如何查找、替换、锁定?
【问题讨论】:
-
Word 的哪个版本?