Word文档分割总结
Word文档分割总结
方法:
1、 word创建子文件实现文件分割
2、 VBA实现
3、 网上分割合并的插件软件
一、 word创建子文件实现文件分割
打开需要分割的文件 >> 视图 >> 大纲视图 >> 单击选择标题内容 >> 单击显示文档 >> 单击创建 >> 保存即可
二、 VBA实现
1、在Word里面打开那个需要分割的文档(假设它的文件名叫做“原始文档.doc”);
2、键入ALT+F11打开VBA编辑器,选择菜单“插入-模块”;
3、粘贴下面的代码:
Option Explicit Sub SplitPagesAsDocuments() Dim oSrcDoc As Document, oNewDoc As Document Dim strSrcName As String, strNewName As String Dim oRange As Range Dim nIndex As Integer Dim fso As Object Set fso = CreateObject("Scripting.FileSystemObject") Set oSrcDoc = ActiveDocument Set oRange = oSrcDoc.Content oRange.Collapse wdCollapseStart oRange.Select For nIndex = 1 To ActiveDocument.Content.Information(wdNumberOfPagesInDocument) oSrcDoc.Bookmarks("\page").Range.Copy oSrcDoc.Windows(1).Activate Application.Browser.Target = wdBrowsePage Application.Browser.Next strSrcName = oSrcDoc.FullName strNewName = fso.BuildPath(fso.GetParentFolderName(strSrcName), _ fso.GetBaseName(strSrcName) & "_" & nIndex & "." & fso.GetExtensionName(strSrcName)) Set oNewDoc = Documents.Add Selection.Paste oNewDoc.SaveAs strNewName oNewDoc.Close False Next Set oNewDoc = Nothing Set oRange = Nothing Set oSrcDoc = Nothing Set fso = Nothing MsgBox "结束!" End Sub
4、键入F5运行,看到“完成!”结束。
5、检查当前文档所在路径下是否生成若干名为“原始文档_n.doc”(n代表其对应原始文档中的第几页)的文档,检查它们的内容是否就对应于原始文档每个页面的内容。
不过那个是按单页拆分的。
如果想按照指定页数拆分,请使用下面的代码,其它步骤和原来那个方案相同。
Option Explicit Sub SplitEveryFivePagesAsDocuments() Dim oSrcDoc As Document, oNewDoc As Document Dim strSrcName As String, strNewName As String Dim oRange As Range Dim nIndex As Integer, nSubIndex As Integer, nTotalPages As Integer, nBound As Integer Dim fso As Object Const nSteps = 100 ' 修改这里控制每隔几页分割一次 Set fso = CreateObject("Scripting.FileSystemObject") Set oSrcDoc = ActiveDocument Set oRange = oSrcDoc.Content nTotalPages = ActiveDocument.Content.Information(wdNumberOfPagesInDocument) oRange.Collapse wdCollapseStart oRange.Select For nIndex = 1 To nTotalPages Step nSteps Set oNewDoc = Documents.Add If nIndex + nSteps > nTotalPages Then nBound = nTotalPages Else nBound = nIndex + nSteps - 1 End If For nSubIndex = nIndex To nBound oSrcDoc.Activate oSrcDoc.Bookmarks("\page").Range.Copy oSrcDoc.Windows(1).Activate Application.Browser.Target = wdBrowsePage Application.Browser.Next oNewDoc.Activate oNewDoc.Windows(1).Selection.Paste Next nSubIndex strSrcName = oSrcDoc.FullName strNewName = fso.BuildPath(fso.GetParentFolderName(strSrcName), _ fso.GetBaseName(strSrcName) & "_" & (nIndex \ nSteps + 1) & "." & fso.GetExtensionName(strSrcName)) oNewDoc.SaveAs strNewName oNewDoc.Close False Next nIndex Set oNewDoc = Nothing Set oRange = Nothing Set oSrcDoc = Nothing Set fso = Nothing MsgBox "结束!" End Sub
三、 网上分割合并的插件软件(请自行搜索word分割文件软件)
总结
方法一比较简单方便,分割较大的word文件比较容易;
方法二分割也不错,但我使用它来分割8M左右大文档(加载需要10多分钟)不可行,报错或者内存不足,小文件还是很方便的;
方法三自动化,大文件没试过。
形而上者谓之道 形而下者谓之器。