|
Word 2003 VBA 代码解决了此问题!代码如下:
' 删除一页
Dim i As String, p As Integer
' 光标定位
InputPageNum:
i = InputBox("你想删除第几页的内容? (1-N)页", "定位页码", "1")
If i = "" Then Exit Sub
If i > Selection.Information(wdNumberOfPagesInDocument) Then MsgBox "文档只有 " & Selection.Information(wdNumberOfPagesInDocument) & " 页!重新输入页码!", vbOKOnly + vbExclamation, "超出范围": GoTo InputPageNum:
If i > Int(i) Or i > Int(i) And i < Int(i + 0.5) Then MsgBox "页码是正整数,请输入正整数!", vbOKOnly + vbExclamation, "输入页码": GoTo InputPageNum:
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=Int(i)
' 选定当前页文本——编码:守柔版主
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(What:=wdGoToPage, Which:=wdGoToNext, Name:=CurrentPage + 1).Start
End If
ActiveDocument.Range(CurrentPageStart, CurrentPageEnd).Select
End With
Selection.Delete |
|