|
原帖由 lan_yu 于 2010-10-15 09:21 发表
非常感谢szqhb 的热心帮助!如果存在两页或多页存为一个文档,因为一个单位(即标题)有多页的情况。谢谢!
不太懂你现在所述的意思,你的要求就是每页存为一个文档啊
如果你是以标题为标志来拆分也是可以的,每个标题必须是统一的字体字号,Home中有相关的例子,自己搜索一下看看
下面是以各标题为二号宋体来拆分的代码
Sub 拆分Word()
Dim myDoc As Document, mytitle As String, a As String, i As Byte
Dim lngStart As Long, lngEnd As Long, myStart As Long, n As Integer
Application.ScreenUpdating = False
Set myDoc = ActiveDocument
myDoc.ActiveWindow.WindowState = wdWindowStateMinimize
a = "\/:*?""<>|"
With myDoc.Content.Find
.ClearFormatting
.Font.Name = "宋体" '各独立小文档标题字体
.Font.Size = 22 '各独立小文档标题字号,22号即二号字体
.Format = True
Do While .Execute
n = n + 1
With .Parent
lngStart = .Start
lngEnd = .Paragraphs(1).Range.End
.MoveUntil Chr(13), wdBackward
If n > 1 Then
Documents.Add.Content.FormattedText = myDoc.Range(IIf(n = 2, 0, myStart), .Start).FormattedText
ActiveDocument.SaveAs myDoc.Path & "\" & mytitle & ".doc"
'ActiveDocument.SaveAs Replace(myDoc.FullName, ".doc", "") & "_" & n - 1 & ".doc"
ActiveDocument.Close
End If
mytitle = Trim(myDoc.Range(lngStart, lngEnd - 1).Text)
For i = 1 To Len(a)
mytitle = Replace(mytitle, Mid(a, i, 1), "")
Next
myStart = .Start
.SetRange lngEnd, lngEnd
End With
Loop
If n > 1 Then
Documents.Add.Content.FormattedText = myDoc.Range(myStart, myDoc.Content.End).FormattedText
ActiveDocument.SaveAs myDoc.Path & "\" & mytitle & ".doc"
'ActiveDocument.SaveAs Replace(myDoc.FullName, ".doc", "") & "_" & n & ".doc"
ActiveDocument.Close
End If
End With
Application.ScreenUpdating = True
myDoc.ActiveWindow.WindowState = wdWindowStateNormal
MsgBox IIf(n > 1, "已将活动文档拆分并另存为" & n & "个小文档。", "活动文档不具备指定的拆分条件。")
End Sub
[ 本帖最后由 szqhb 于 2010-10-19 23:55 编辑 ] |
|