我想计算 MS word 文档中选定文本的行数。我想出了代码:
Sub Count_Lines()
ActiveDocument.ComputeStatistics (wdStatisticLines)
MsgBox ("The document contains " & NumLines & " Lines")
End sub
但它实际上计算了整个文档的行数。
任何人都可以帮助找到只能计算选定行的代码吗?
最佳答案
只需使用 Selection.Range
对象而不是 ActiveDocument
Sub Count_Lines()
MsgBox ("The selection contains " & Selection.Range.ComputeStatistics(wdStatisticLines) & " Lines")
End Sub
关于vba - 计算 MS Word 中选定的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48457246/