【发布时间】:2018-03-24 17:31:07
【问题描述】:
在这段代码中,我想做以下事情:
- 如果单词以字母 M 结尾,则替换为字母 N。
- 如果单词以字母 N 结尾,则替换为字母 M。
-
我不太了解如何使用 IF - Then 语句。 任何帮助将不胜感激。
Sub find_end() Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "[nm]>" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .MatchWildcards = True Selection.Find.Execute With Selection If Selection.Find.Found = n Then Selection.TypeText Text:=m ElseIf Selection.Find.Found = m Then Selection.TypeText Text:=n End If End Sub
【问题讨论】:
-
您的代码需要进行多次更正(缺少两个 'End With';引号围绕 = "m" 和 = "n" 等。但是,您的代码不会遍历所有事件。看看以下作为如何查找所有事件的示例。如果您将其更改为“If Selection.Text = “n””,您的 if 将起作用,但您有“Selection.Find.Found”,它返回一个真/假。
标签: vba if-statement ms-word find replacewith