在选择中查找并替换 [英] Find and Replace in just the selection
本文介绍了在选择中查找并替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下宏.它将形式为x.x的数字更改为x,x.它被记录下来,我添加了IF语句以确保选择了文本,以防止用户在整个文档中使用它.
I have the following macro. It changes numbers of the form x.x to x,x. It was recorded and I added the IF statement to make sure a text is selected to prevent the user from doing it on the whole document.
Sub fixComma()
'
' fixComma Macro
'
'
If (Selection.Start <> Selection.End) Then
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.LanguageID = wdEnglishUS
With Selection.Find
.Text = "([0-9]).([0-9])"
.Replacement.Text = "\1,\2"
.Forward = True
.Wrap = wdFindAsk
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
Else
MsgBox "Nothing is selected, Macro terminated"
End If
End Sub
问题在于它正在更改整个文档,而不仅仅是更改选择.
The problem is it is changing the whole document and not just the selection.
推荐答案
更改
Selection.Find.Execute Replace:=wdReplaceAll
到
Selection.Find.Execute Replace:=wdReplaceOne
将得到它,因此选择中x.x的第一个实例将更改为x,x而不是整个文档.
Will get it so the first instance of x.x in a selection will change to x,x and not the whole document.
:如果只希望更改选定区域中的所有项目,请保留:
if you want all items in a selected area only to change then keep:
Selection.Find.Execute Replace:=wdReplaceAll
但是要改变
.Wrap = wdFindAsk
到
.Wrap = wdFindStop
这篇关于在选择中查找并替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文