下面代码把原文档按照指定的标识(这里是“END”)进行拆分。拆分之后的文档生成在源文档当前目录下,文件名后面附加来自“_1”、“_2”、“_3”等。
Optio360问答n Explicit
Const Token = 'END'
Sub SplitDocumentByToken()
Dim o果段绝资NewDoc As Docum己乙六米景永不ent
Dim strSrcName As String, strNewName As String
Dim nStart As Integer, nEnd As Integer, nIndex As Integer
Dim fContinue As 门穿取扬鲜富及办特Boolean
Dim fso As Object
Set fso = CreateObject('Scripting.FileSystemObject')
strSrcName = ActiveDocument.FullName
nIndex = 1
fContinue = True
Selection.StartOf WdUnits.wdStory
Do While fContinue
nStart = Selection.Start
Selection.台位密机械科静至啊Find.ClearForma灯赶作连服界号tting
With Selection.Find
.Text = '^13' & Token & '^13'
.Replacement.Text = ''
.副担连精然或罗相危兰从Forward = True
.W书扩想rap = WdFindW也章静普粉rap.wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
If Selection.Find.Execute Then
nEnd = Selection.End
Else
nEnd = ActiveDocument.Content.End
fContinue = False
End If
ActiveDocument.Range(nStart, nEnd).Copy
strNewName = fso.BuildPath(fso.GetParentFolderName(strSrcName), _
fso.GetBaseName(strSrcName) & '_' & nIndex & '.' & fso.GetExtensionName(strSrcName))
Set oNewDoc = Docu茶ments.Add
Selection.Paste
oN宗电优若得无低容房改ewDoc.SaveAs strNewName
oNewDoc.Clos零良品批商章布e False
nIndex = nIndex + 1
Selection.Collapse WdCollap占seDirection.wdCollapseEnd
Lo标松善终题编被屋安op
Set oNewD限oc = Nothing
Set fso = Nothing
MsgBox '结束!'
End Sub
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。