|
* 楼主,附件文档第一段落首行有缩进并非居中,请改正之。
* 请打开要拆分的文档试用下面的宏:(此宏可能不适合有表格的文档!拆分结果请见"D:\TextSplit")
- Sub TextSplit()
- Dim doc As Document, i&, p&, s&, t$, j&, k$, y$, x$
- With ActiveDocument
- y = .FullName
- p = .ComputeStatistics(wdStatisticPages)
- k = (Split(y, ".")(1))
- Do
- i = i + 1
- With Selection
- .GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:=i + 1
- If Asc(.Previous) <> 12 Then .InsertBreak Type:=wdSectionBreakNextPage
- End With
- Loop Until i = p - 1
- s = .Sections.Count
- End With
- Do
- Set doc = ActiveDocument
- With doc
- j = j + 1
- .Sections(j).Range.Select
- If j = s Then
- .Range(Start:=0, End:=Selection.Start).Delete
- Else
- .Range(Start:=Selection.End, End:=.Content.End).Delete
- If j > 1 Then .Range(Start:=0, End:=Selection.Start).Delete
- End If
- .Content.Find.Execute "^b", , , 0, , , , , , "", 2
- Do While .Paragraphs.Last.Range.Text = vbCr
- .Paragraphs.Last.Range.Delete
- Loop
- Selection.HomeKey 6
- ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitBestFit
- If Len(Dir("D:\TextSplit", 16)) = 0 Then MkDir "D:\TextSplit"
- x = .Paragraphs(3).Range.Text
- x = Replace(x, vbCr, "")
- If k = "docx" Then
- .SaveAs2 FileName:="D:\TextSplit" & "" & x & ".docx", FileFormat:=wdFormatXMLDocument
- Else
- .SaveAs2 FileName:="D:\TextSplit" & "" & x & ".doc", FileFormat:=wdFormatDocument
- End If
- .Close
- If j = s Then Exit Do
- Documents.Open FileName:=y
- End With
- Loop
- t = "D:\TextSplit"
- MsgBox "Completed!" & vbCr & "Save Path - " & t, 0 + 48
- End Sub
复制代码 |
|