Word VBA 如何获取当前选择区总行数?
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
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
追问
请看清楚:是“当前选择区总行数”
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询