Msword搜索宏

发布于 2025-01-31 21:17:43 字数 1057 浏览 2 评论 0原文

当我在未指定范围的情况下进行搜索时,搜索开始在活动页面上:

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
    .Text = "house"
    .Replacement.Text = "apartment"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = True
End With
Selection.Find.Execute

如果我使用范围,它总是从范围的开头开始,

ActiveDocument.StoryRanges(wdMainTextStory).select
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
    .Text = "house"
    .Replacement.Text = "apartment"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = True
End With
Selection.Find.Execute

有人知道一种在使用范围时在活动页面中启动搜索的方法吗?

通过Active页面,我的意思是带有光标的页面。

另外,我需要搜索脚注和尾注。这就是使用故事范围的原因,这似乎迫使搜索从文档的开头开始。

When I search without specifying the range, the search starts at the active page:

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
    .Text = "house"
    .Replacement.Text = "apartment"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = True
End With
Selection.Find.Execute

If I use a range, it always starts at the beginning of the range

ActiveDocument.StoryRanges(wdMainTextStory).select
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
    .Text = "house"
    .Replacement.Text = "apartment"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = True
End With
Selection.Find.Execute

Anyone know a way to start the search in the active page while using a range?

By active page, I mean the page with the cursor.

Also, I need to search footnotes and endnotes. That's the reason for using storyranges, which seems to force the search to start at the beginning of the document.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

从﹋此江山别 2025-02-07 21:17:43

例如:

Dim findRange As Range
Set findRange = Selection.Range
With findRange.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "house"
    .Replacement.Text = "apartment"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = True
    .Execute
End With

请注意,由于您已经设置了.wrap = wdfindContinue它在查找开始时没有区别,因为它会搜索整个文档。

For example:

Dim findRange As Range
Set findRange = Selection.Range
With findRange.Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "house"
    .Replacement.Text = "apartment"
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = True
    .Execute
End With

Please note that as you have set .Wrap = wdFindContinue it makes no difference where Find starts as it will search the entire document anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文