如何在word表格中用VBA得到当前光标所在得单元格得位置

2024-12-11 22:12:12
推荐回答(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