仅在选择中查找和替换 [英] Find and Replace in just the selection

查看:24
本文介绍了仅在选择中查找和替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下宏.它将 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆