[英]MS Word macro — special handling for top of page
我试图编写一个MS Word宏来下拉一行并键入一个特定的短语,除非光标位于文档的最顶部或紧接在“硬”分页符之后,在这种情况下,它仅应键入消息。 代码非常像这样-
If <TOP OF PAGE> Then
Selection.TypeText Text:="top of page"
Else
Selection.TypeParagraph
Selection.TypeText Text:="not top of page"
End If
-但我不知道用于测试光标是否在页面顶部的特定语法。 有人可以填写我吗? 我的软件版本是MS Word2003。谢谢。
您可以使用Selection.Information(wdFirstCharacterLineNumber) = 1
。
If Selection.Information(wdFirstCharacterLineNumber) = 1 Then
Selection.TypeText Text:="top of page"
Else
Selection.TypeParagraph
Selection.TypeText Text:="not top of page"
End If
Selection.Information(wdFirstCharacterLineNumber)
将返回该页面内当前选择的行号。 参见MSDN 。
PS:我已经用Word 2010测试了此功能,但无法访问以前的版本。 所以试试吧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.