Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sub 宏1()

Dim docNew As Document
Dim k As Integer
Dim ks As String
k = 0
Set docNew = Documents.Add
jk0 = "D:\gstk_doc\" 'doc文档路径
s = Dir(jk0, vbDirectory)
Do While s <> "" ' 开始循环。
If s <> "." And s <> ".." Then
Set doc = Documents.Open(jk0 & s, ReadOnly:=True, Visible:=True) '打开 doc文件
doc.Activate

For Each i In ActiveDocument.Paragraphs
If Left(Trim(i.Range.Text), 2) = "``" Then
k = k + 1
If k < 10 Then
ks = "t000" & Trim(Str(k))
Else
If k < 100 Then
ks = "t00" & Trim(Str(k))
Else
If k < 1000 Then
ks = "t0" & Trim(Str(k))
Else
ks = "t" & Trim(Str(k))
End If
End If
End If
i.Range.Copy
docNew.Close SaveChanges:=wdSaveChanges
Set docNew = Documents.Add(Visible:=False)
With docNew
.Content.Paragraphs.Last.Range.Select
' Selection.Paste '这是被选中的文档被粘贴覆盖,
.SaveAs FileName:="D:\gstk_doc\gstk_dt\" & ks & Mid(Trim(i.Range.Text), 3, 15) & ".doc"
End With
' docNew.Close
Else
i.Range.Copy
With docNew
.Content.Paragraphs.Last.Range.Select
Selection.Paste '这是被选中的文档被粘贴覆盖,
End With
End If
Next i
doc.Close
End If
s = Dir ' 查找下一个目录。
Loop

End Sub
VB

Posted

1 solution

I don't know why some documents can not be parted and saved in separate files.thank you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900