|
楼主 |
发表于 2022-5-18 11:29
|
显示全部楼层
自己也学着鼓捣一下,未优化:
- Sub DelPage()
- Dim Pn As Long, Rng As Range, P As Integer
- Pn = ThisDocument.BuiltInDocumentProperties(wdPropertyPages)
- For P = 1 To Pn
- If P = Pn Then
- Set Rng = ThisDocument.Range(Start:=ThisDocument.GoTo(wdGoToPage, wdGoToAbsolute, P).Start)
- Else
- Set Rng = ThisDocument.Range(Start:=ThisDocument.GoTo(wdGoToPage, wdGoToAbsolute, P).Start, End:=ThisDocument.GoTo(wdGoToPage, wdGoToAbsolute, P + 1).Start)
- End If
- If Replace(Rng.Text, Chr(13), "") = "" Or Replace(Rng.Text, Chr(13), "") = Chr(12) Then
- Rng.Text = Replace(Rng.Text, Chr(13), "")
- Rng.Text = ""
- Pn = ThisDocument.BuiltInDocumentProperties(wdPropertyPages)
- If P <> Pn Then
- P = P - 1
- Else
- Set Rng = ThisDocument.Range(Start:=ThisDocument.GoTo(wdGoToPage, wdGoToAbsolute, Pn - 1).Start, End:=ThisDocument.GoTo(wdGoToPage, wdGoToAbsolute, Pn + 1).Start)
- If InStr(1, Rng.Text, Chr(12)) > 0 Then
- Rng.Characters(InStr(1, Rng.Text, Chr(12))) = ""
- Else
- Set Rng = ThisDocument.Range(Start:=ThisDocument.GoTo(wdGoToPage, wdGoToAbsolute, P).Start)
- Rng.Select: Selection.Delete
- End If
- Exit For
- End If
- End If
- Next
- End Sub
复制代码
|
|