使用选择对象 (vba) 从 word 文档中获取一行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7835644/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 12:05:11  来源:igfitidea点击:

Getting a line from a word document using Selection object (vba)

vba

提问by badmaash

How can i get a line from a word document using the Selection object in VBA script? Something like this:

如何使用 VBA 脚本中的 Selection 对象从 Word 文档中获取一行?像这样的东西:

Selection.MoveDown Unit:=wdLine, Count:=15
'print the 15th line here

EDIT: When i do:

编辑:当我这样做时:

Selection.MoveDown Unit:=wdLine, Count:=15
MsgBox (Selection.Text)

It prints only the first character of the line.

它只打印该行的第一个字符。

回答by Fionnuala

You need to expand the selection:

您需要扩展选择:

Selection.MoveDown Unit:=wdLine, Count:=15
Selection.Expand wdLine
MsgBox (Selection.Text)