|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Private Sub document_close() On Error Resume Next Application.CommandBars("text").Controls("选定当前页").Delete '恢复原有菜单 End Sub Private Sub document_open() Dim half As Byte On Error Resume Next Dim newbutton As CommandBarButton Application.CommandBars("text").Controls("选定当前页").Delete '预防性删除 half = Int(Application.CommandBars("text").Controls.Count / 2) '中间位置 Set newbutton = Application.CommandBars("text").Controls.Add(Type:=msoControlButton, Before:=half) With newbutton .Caption = "选定当前页" '命令名称 .FaceId = 100 '命令的faceid .Visible = True .OnAction = "selectcurrentpage" '指定响应过程名 End With End Sub Sub selectcurrentpage() Dim currentpagestart As Long, currentpageend As Long Dim currentpage As Integer, Pages As Integer On Error Resume Next With Selection currentpage = .Information(wdActiveEndPageNumber) Pages = .Information(wdNumberOfPagesInDocument) currentpagestart = .GoTo(What:=wdGoToPage, Which:=wdGoToNext, Name:=currentpage).start If currentpage = Pages Then '两者相等则最后位置为文档最后位置 currentpageend = ActiveDocument.Content.End Else currentpageend = .GoTo(wdGoToPage, Which:=wdGoToNext, Name:=currentpage + 1).start End If ActiveDocument.Range(currentpagestart, currentpageend).Select End With End Sub 这是守柔版主以前写的选定当前页的程序,在《守柔WORD编程代码集》中可以看到。 |
|