word vba 怎么获取当前光标所在页码,并获取该页有多少行

2025-03-01 20:15:29
推荐回答(1个)
回答1:

Sub Macro2()
   Dim r, p, r0, p0, rr, pp
    p= Selection.Information(wdActiveEndPageNumber) '当前页码
    r= Selection.Information(wdFirstCharacterLineNumber) '当前行
    
    '数行数
   p0 = p
   rr = r
   Do
       Selection.MoveDown Unit:=wdLine, Count:=1
       pp = Selection.Information(wdActiveEndPageNumber)
       r0 = Selection.Information(wdFirstCharacterLineNumber)
       If pp > p Then
           '退回原处
           Selection.MoveUp Unit:=wdLine, Count:=(rr - r + 1)
           Exit Do
       End If
       If rr = r0 Then
           '退回原处
          Selection.MoveUp Unit:=wdLine, Count:=(rr - r)
           Exit Do
       End If
       rr = r0
    Loop
   MsgBox "当前页码:" & p & vbCrLf & "本页总行数:" & rr
End Sub

 申请加悬赏分!!!