word vba怎么查找字符串,并获取所在页码、所在行数

2025-03-09 20:03:19
推荐回答(1个)
回答1:

Private Sub CommandButton1_Click()
   Dim p, r, s, t
    s= "石膏板造型顶"
   With Selection.Find
       .ClearFormatting
       .MatchWholeWord = True
       .MatchCase = False
       t = .Execute(FindText:=s)
   End With
    p= Selection.Information(wdActiveEndPageNumber)
    r= Selection.Information(wdFirstCharacterLineNumber)
   If t Then
       MsgBox "成功,已找到“" & s & "”" & vbCrLf & _
           "页码:"& p & vbCrLf & "行数:" & r, vbOKOnly, _
           "成功"
   Else
       MsgBox "很遗憾,没有找到“" & s & "”", vbOKOnly, _
           "遗憾"
   End If
End Sub

 写代码很辛苦,好心的楼主请  救济  点儿  悬赏分