萬盛學電腦網

 萬盛學電腦網 >> WORD教程 >> WORD使用技巧 >> VBA全選word當前頁代碼

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環境下使用。

copyright © 萬盛學電腦網 all rights reserved