电脑教程
位置:首页>> 电脑教程>> office教程>> VBA全选word当前页代码

VBA全选word当前页代码

  发布时间:2023-12-13 10:11:06 

标签:VBA全选word当前页代码

下面的代码的功能是,全选word文档的当前页,注意,是当前页,即插入条所在的页,而不是全文。

Dim CurrentPageStart As Long, CurrentPageEnd As Long, myRange As Range

Dim Currentpage As Integer, Pages As Integer

On Error Resume Next

Currentpage = Selection.Information(wdActiveEndPageNumber)

Pages = Selection.Information(wdNumberOfPagesInDocument)

CurrentPageStart = Selection.GoTo(what:=wdGoToPage, Which:=wdGoToNext, Name:=Currentpage).start

If Currentpage = Pages Then

CurrentPageEnd = ActiveDocument.Content.End

Else

CurrentPageEnd = Selection.GoTo(what:=wdGoToPage, Which:=wdGoToNext, Name:=Currentpage + 1).start

End If

Set myRange = ActiveDocument.Range(CurrentPageStart, CurrentPageEnd)

myRange.Select

注意,以上代码在VBA环境下使用。

0
投稿

猜你喜欢

手机版 电脑教程 asp之家 www.aspxhome.com