本帖最后由 小花鹿 于 2017-5-23 23:01 编辑
阿杜分享:
Sub 主程序()
Dim rg As Range
Set rg = IIf(Selection.Type = wdSelectionIP, ActiveDocument.Range, Selection.Range)
Call DP(rg)
End Sub
Function DP(selectRange As Range)
' 1、区域中的软回车替换为硬回车;
' 2、 清除区域中的段前和段尾空白;
' 3 、清除区域中的空段落
sr$ = Chr$(32) & Chr$(9) & ChrW(12288) & ChrW(160)
With selectRange
With .Find
.Execute "^11", , , 1, , , , 0, , "^p", 2
.Execute "^p^w", , , 0, , , , 0, , "^p", 2
.Execute "^w^p", , , 0, , , , 0, , "^p", 2
.Execute "^13{2,}", , , 1, , , , 0, , "^p", 2
End With
With .Paragraphs(1).Range
n& = Len(.Text) - 1: .SetRange .Start, .Start
If .MoveEndWhile(sr, n) <> 0 Then: .Text = Empty
End With
End With
End Function
Sub deletepage()
Dim p, doc As Document, s, i&, sp As Shape
p = ActiveDocument.ActiveWindow.ActivePane.Pages.Count
For i = p To 1 Step -1
With ActiveDocument.ActiveWindow.ActivePane.Pages(i).Rectangles(1).Range
s = .Text: n = 0
For Each sp In .ShapeRange
If sp.WrapFormat.Type <> 7 Then
n = n + 1
End If
Next
s = .Text
s = Replace(Replace(s, Chr(13), ""), Chr(12), "")
If s = "" And n = 0 Then
.Delete
End If
End With
Next i
End Sub
Sub splitpage()
Dim p As Page, doc As Document
For Each p In ActiveDocument.ActiveWindow.ActivePane.Pages
With p.Rectangles(1).Range
n = n + 1
If Right(.Text, 1) = Chr(13) Then .End = .End - 1
Set doc = Documents.Add(, , , 0)
doc.Bookmarks("\endofdoc").Range.FormattedText = .FormattedText
doc.ActiveWindow.View.Type = 4
doc.SaveAs ThisDocument.Path & "\" & n & ".docx"
doc.Close 0
End With
Next
End Sub
|