|
楼主 |
发表于 2022-5-9 20:49
|
显示全部楼层
弄了好半天,总算拼凑出来:
- Sub delpm() 'ok
- Const wdPageBreak = 7
- Const wdGoToPage = 1
- Const wdGoToAbsolute = 1
- Dim oDoc As Document, oRng As Range, p As Long, myRange As Range, x As Long, y As Long
- Set oDoc = Word.ActiveDocument
- p = oDoc.Range.Information(wdNumberOfPagesInDocument) '总页数
- x = Selection.GoTo(what:=wdGoToPage, Which:=wdGoToNext, Name:=Currentpage).Start
- y = oDoc.Content.End
- Set myRange = ActiveDocument.Range(x, y) 'CurrentPageEnd
- myRange.Select
- Selection.Delete
- For i = p To p - 1 Step -1
- With oDoc.GoTo(wdGoToPage, Which:=wdGoToAbsolute, count:=p - 1).Find
- .ClearFormatting
- .MatchWildcards = False
- .Text = "^m" '分页符
- .Execute ReplaceWith:="", Replace:=wdReplaceAll
- .Text = "^b" '分节符
- .Execute ReplaceWith:="", Replace:=wdReplaceAll
- End With
- Next
- End Sub
复制代码 |
|