word原文档如何分段保存成新的word文档
我把我原来只适用于2007的代码修改了一下,下面这个步骤应该就可以在Word2003上将当前文档按照段落保存成多份新文档:
1、首先在Word里面打开需要分割的原始文档;
2、键入Alt+F11打开VBA编辑器;
3、选择菜单命令“插入-模块”;
4、在代码编辑区中输入如下代码:
Option Explicit
Sub SplitCurrentDocumentByParagraph()
Const strFileExtension = ".doc"
Dim oSourceDoc As Document
Dim oNewDoc As Document
Dim oParagraph As Paragraph
Dim strTargetFileName As String
Dim nIndex As Integer
Set oSourceDoc = ActiveDocument
nIndex = 1
For Each oParagraph In oSourceDoc.Paragraphs
oParagraph.Range.Copy
Set oNewDoc = Documents.Add
oNewDoc.Range.Paste
strTargetFileName = Replace(oSourceDoc.FullName, strFileExtension, "_" & nIndex & strFileExtension)
oNewDoc.SaveAs2 strTargetFileName
oNewDoc.Close
nIndex = nIndex + 1
Next
MsgBox "完成"
End Sub
5、键入F5,运行。
检查在原文档相同目录下生成了若干个doc文件,文件名是原文件后面加_1、_2、_3等,每个doc文件对应原来的一个段落。
不知是不是楼主需要的效果?
版权声明:本文由哟品培原创或收集发布,如需转载请注明出处。