积极答复者
求助:如何判断word文档模板中每页的最后一个字?

问题
答案
-
你好,
下面有一段示例代码
Sub test() Dim myRange As Range Set myRange = ActiveDocument.Range(0, 0) '这里Name参数传2的意思是去第2页。 Set myRange = myRange.GoTo(what:=wdGoToPage, Name:="2") Set myRange = myRange.GoTo(what:=wdGoToBookmark, Name:="\page") '执行了上面几行代码之后,myRange即为指定页了(这里是第2页)。然后可以通过 'Range.Text 属性获取本页的全部文字。 之后可以用VBA的字符串函数Right() '来获取最后一个字符。 MsgBox myRange.text End Sub
出处 http://word.mvps.org/FAQs/MacrosVBA/SelectCurPage.htm
希望能有帮助。
Quist Zhang [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Ego JiangModerator 2013年5月10日 9:26
全部回复
-
你好,
下面有一段示例代码
Sub test() Dim myRange As Range Set myRange = ActiveDocument.Range(0, 0) '这里Name参数传2的意思是去第2页。 Set myRange = myRange.GoTo(what:=wdGoToPage, Name:="2") Set myRange = myRange.GoTo(what:=wdGoToBookmark, Name:="\page") '执行了上面几行代码之后,myRange即为指定页了(这里是第2页)。然后可以通过 'Range.Text 属性获取本页的全部文字。 之后可以用VBA的字符串函数Right() '来获取最后一个字符。 MsgBox myRange.text End Sub
出处 http://word.mvps.org/FAQs/MacrosVBA/SelectCurPage.htm
希望能有帮助。
Quist Zhang [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- 已标记为答案 Ego JiangModerator 2013年5月10日 9:26