简体   繁体   English

VBA for MS word在文档中查找文本

[英]VBA for MS word to find text in document

https://stackoverflow.com/a/11624006/1553562 https://stackoverflow.com/a/11624006/1553562

How do i limit my search to a limited range of documents taken as input from the user??? 如何将搜索限制为从用户输入的有限范围的文档???

This will let you specify your range from Page 3 to Page 20 这将允许您指定从第3页到第20页的范围

Sub Sample()
    Dim rng As Range
    Dim StartPage As Long, EndPage As Long

    StartPage = 3: EndPage = 20

    Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=StartPage

    Set rng = Selection.Range

    Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=EndPage

    rng.End = Selection.Bookmarks("\Page").Range.End

    '~~> Now you have got your range. Do the necessary action here
    With rng

    End With
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM