|
Sub lx()
Dim wd1 As Document, wd As Document, m$
Application.ScreenUpdating = False
Set wd1 = ThisDocument
Do
Selection.EndKey unit:=wdStory
With Selection.Find
.Text = "文件名称"
.Forward = False
.Wrap = wdFindStop
.Execute
If .Found = True Then
Selection.MoveUp unit:=wdParagraph
Selection.EndKey unit:=wdStory, Extend:=wdExtend
Selection.Cut
Set wd = Documents.Add
wd.Range.Paste
m = wd.Tables(1).Range.Cells(2).Range.Text
m = Left(m, Len(m) - 2)
On Error Resume Next
If Dir(wd1.Path & "\拆分文件\") = "" Then MkDir (wd1.Path & "\拆分文件")
wd.SaveAs2 (wd1.Path & "\拆分文件\" & m & ".docx")
wd.Close
Else
Exit Do
End If
End With
Loop
MsgBox "拆分完毕"
Application.ScreenUpdating = True
End Sub
|
|