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

时间:2012-08-01 07:21:48

标签: vba ms-word word-vba

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

如何将搜索范围限制为从用户输入的有限范围的文档???

1 个答案:

答案 0 :(得分:3)

这将允许您指定从第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