简体   繁体   English

MS Word宏-页面顶部的特殊处理

[英]MS Word macro — special handling for top of page

I'm trying to write an MS Word macro to drop down one line and type a certain phrase unless the cursor at the very top of the document or following a "hard" page break, in which case it should only type the message. 我试图编写一个MS Word宏来下拉一行并键入一个特定的短语,除非光标位于文档的最顶部或紧接在“硬”分页符之后,在这种情况下,它仅应键入消息。 The code goes pretty much like this -- 代码非常像这样-

If <TOP OF PAGE> Then
  Selection.TypeText Text:="top of page"  
Else
  Selection.TypeParagraph
  Selection.TypeText Text:="not top of page"  
End If

-- but I don't know the specific syntax for testing whether the cursor is at the top of a page. -但我不知道用于测试光标是否在页面顶部的特定语法。 Can anyone fill me in? 有人可以填写我吗? My software version is MS Word 2003. Thanks. 我的软件版本是MS Word2003。谢谢。

You could use Selection.Information(wdFirstCharacterLineNumber) = 1 . 您可以使用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) will return the line number of the current selection within that page. Selection.Information(wdFirstCharacterLineNumber)将返回该页面内当前选择的行号。 See MSDN . 参见MSDN

PS: I have tested this with Word 2010 and I don't have access to previous version. PS:我已经用Word 2010测试了此功能,但无法访问以前的版本。 So, give it a try. 所以试试吧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM