跳到主要内容

如何将文档分成多个单词?

作者:阿曼达·李 最后修改时间:2020-12-23

如果您有一个庞大的Word文档,需要将其拆分为多个文档,请花几分钟阅读本教程。 本教程将向您展示两种将文档拆分为多个文档的方法。


使用VBA通过指定的分隔符拆分Word文档

此方法将引入VBA来通过Word中指定的分隔符将Word文档拆分,而不是手动将文档拆分为多个文档。 请执行以下操作:

1。 按 Alt + F11键 一起打开Microsoft Visual Basic for Application窗口;

2。 点击 插页 > 模块,然后将以下VBA代码粘贴到新打开的“模块”窗口中。

VBA:通过分隔符将Word文档拆分为多个文档

Sub SplitNotes(delim As String, strFilename As String)
Dim doc As Document
Dim arrNotes
Dim I As Long
Dim X As Long
Dim Response As Integer
arrNotes = Split(ActiveDocument.Range, delim)
Response = MsgBox("This will split the document into " & UBound(arrNotes) + 1 & " sections.Do you wish to proceed?", 4)
If Response = 7 Then Exit Sub
For I = LBound(arrNotes) To UBound(arrNotes)
If Trim(arrNotes(I)) <> "" Then
X = X + 1
Set doc = Documents.Add
doc.Range = arrNotes(I)
doc.SaveAs ThisDocument.Path & "\" & strFilename & Format(X, "000")
doc.Close True
End If
Next I
End Sub
Sub test()
'delimiter & filename
SplitNotes "///", "Notes "
End Sub

3。 然后点击 运行 按钮或按F5键应用VBA。

4。 在弹出的Microsoft Word文档中,请单击“是”按钮继续。

请注意:
(1)确保将分隔符添加为与 “ ///” 在子测试中,您要分隔的每个文本部分之间的文档。 此外,您可以更改 “ ///” 任何分隔符,以满足您的需要。
(2)您可以更改文件 “笔记” 在子测试中以满足您的需求。
(3)分割文件将与原始文件保存在同一位置。
(4)不需要在原始文件的末尾添加定界符,如果这样做,则分割后会有空白文档。

使用VBA按页面拆分Word文档

这是另一个VBA,可帮助您在Word中快速将一个Word文档按页面拆分成多个。 请执行以下操作:

1。 按 Alt + F11键 一起打开Microsoft Visual Basic for Application窗口;

2。 点击 插页 > 模块,然后将以下VBA代码粘贴到新打开的“模块”窗口中。

VBA:在Word中按页面将文档拆分为多个文档

Sub SplitIntoPages()
Dim docMultiple As Document
Dim docSingle As Document
Dim rngPage As Range
Dim iCurrentPage As Integer
Dim iPageCount As Integer
Dim strNewFileName As String
Application.ScreenUpdating = False 'Makes the code run faster and reduces screen _
flicker a bit.
Set docMultiple = ActiveDocument 'Work on the active document _
(the one currently containing the Selection)
Set rngPage = docMultiple.Range 'instantiate the range object
iCurrentPage = 1
'get the document's page count
iPageCount = docMultiple.Content.ComputeStatistics(wdStatisticPages)
Do Until iCurrentPage > iPageCount
If iCurrentPage = iPageCount Then
rngPage.End = ActiveDocument.Range.End 'last page (there won't be a next page)
Else
'Find the beginning of the next page
'Must use the Selection object. The Range.Goto method will not work on a page
Selection.GoTo wdGoToPage, wdGoToAbsolute, iCurrentPage + 1
'Set the end of the range to the point between the pages
rngPage.End = Selection.Start
End If
rngPage.Copy 'copy the page into the Windows clipboard
Set docSingle = Documents.Add 'create a new document
docSingle.Range.Paste 'paste the clipboard contents to the new document
'remove any manual page break to prevent a second blank
docSingle.Range.Find.Execute Findtext:="^m", ReplaceWith:=""
'build a new sequentially-numbered file name based on the original multi-paged file name and path
strNewFileName = Replace(docMultiple.FullName, ".doc", "_" & Right$("000" & iCurrentPage, 4) & ".doc")
docSingle.SaveAs strNewFileName 'save the new single-paged document
iCurrentPage = iCurrentPage + 1 'move to the next page
docSingle.Close 'close the new document
rngPage.Collapse wdCollapseEnd 'go to the next page
Loop 'go to the top of the do loop
Application.ScreenUpdating = True 'restore the screen updating
'Destroy the objects.
Set docMultiple = Nothing
Set docSingle = Nothing
Set rngPage = Nothing
End Sub 

3。 然后点击 运行 按钮或按下 F5 应用VBA的关键。

请注意: 拆分文档将与原始文件保存在同一位置。


使用 Kutools for Word 按标题/页面/分节符/分页符拆分 Word 文档

如果您安装了 Kutools for Word,您可以应用它 分裂 功能可轻松在Word中按页面,标题,分节符或分页符将一个文档拆分为多个文档。

Kutools for Word 是终极的 Word 插件,可简化您的工作并提高您的文档处理技能。 立即获取!

1点击 Kutools 加 > 分裂 使之成为可能 分裂 功能。

2。 在屏幕上打开的“拆分”对话框中,您可以执行以下操作:

(1)从 分割为 下拉列表。
此功能支持6种拆分方式:标题1,分页符,分节符,页面,每n页和自定义页面范围,如下面的屏幕截图所示:

(2)点击 浏览 按键  指定 将拆分文档保存到的目标文件夹;

(3)在关键字栏中输入关键字作为新文档名称的前缀。 文件前缀 框。

提示:
(1)如果指定拆分当前文档 每n页,您需要在 每n页 框;

(2)如果您指定按自定义页面范围分割当前文档,则需要在这些自定义页面范围中输入用逗号分隔的自定义页面范围。 框,例如,在框中键入1、3-5、12。

3。 点击 Ok 按钮开始拆分。

然后,以指定的拆分方式拆分当前文档,并将新文档批量保存到目标文件夹中。

选项卡式浏览和编辑多个 Word 文档,就像在 Chrome 和 Edge 中一样!

就像在 Chrome、Safari 和 Edge 中浏览多个网页一样,Office Tab 可让您在单个窗口中打开和管理多个 Word 文档。现在只需单击其选项卡即可在文档之间轻松切换!
立即免费试用所有功能!

使用Firefox在一个窗口中浏览多个Word文档


相关文章:


最佳办公生产力工具

Kutools for Word - 通过 Over 提升您的文字体验 100 显着特点!

🤖 Kutools 人工智能助手:用人工智能改变你的写作 - 生成内容  /  重写文本  /  总结文件  /  快速获得答案,全部在Word中

📘 文档掌握: 分页  /  合并文件  /  以各种格式导出选择(PDF/TXT/DOC/HTML...)  /  批量转换为PDF  /  将页面导出为图像  /  一次打印多个文件...

内容编辑: 批量查找和替换 跨多个文件  /  调整所有图片的大小  /  转置表行和列  /  将表格转换为文字...

🧹 轻松清洁: 移开 多余的空间  /  分节符  /  所有标题  /  文本框  /  超链接  / 如需更多拆卸工具,请前往 删除组...

创意插入: 插 千位分隔符  /  复选框  /  单选按钮  /  扫码支付  /  条码  /  对角线表  /  公式标题  /  图片说明  /  表标题  /  多张图片  / 发现更多 插入组...

🔍 精准选择:精确定位 特定页面  /    /  形状  /  标题段落  / 增强导航功能 更多 选择功能...

星级增强: 导航到任何位置  /  自动插入重复文本  /  在文档窗口之间切换  /  11 转换工具...

👉 想要尝试这些功能吗?立即下载 Kutools for Word! 🚀
 
Comments (45)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
VBA: Split Document into Multiple Documents by Page in Word - in this when we run it, outcome comes in portrait layout only. If original doc is in landscape then full data of the original doc does not come in the pages breaked by this vba.. There must be seperate vba for portrait and landscape docs.
This comment was minimized by the moderator on the site
I use the "split"-function of "Kutools For Word 9.00" with "header 1" and it works for 48 documents and then it simply stops without any message, as if it wohl have been finished. But I have 700 "header 1" in a 2000 pages document!
Is it simply too much for the tool or is there any other reason?
This comment was minimized by the moderator on the site
your code add new blank page in every page
This comment was minimized by the moderator on the site
This worked fine up until yesterday with Office365, but now I constantly get a runtime error '4605' stating this command is not available. Sometimes at the first page, sometimes at the 3rd page...I can't make it past 3 pages anymore. It happens with line 28 above...

docSingle.Range.Paste 'paste the clipboard contents to the new document
This comment was minimized by the moderator on the site
I've got this error too - Did you get anywhere with it?


Thanks
This comment was minimized by the moderator on the site
yes...i have to run it on the local hard drive. if i run it on a network file or with RemotePC it. has something to do with the script having to wait too long in between commands and it errors out copy and pasting to the clipboard. hope that helps!!
This comment was minimized by the moderator on the site
I copied the document distribution macro 'Split Word Document By Specified Delimiter With VBA', but in the line of 'sub test', the software reads it as a new macro and there are two macros here.
There are no comments posted here yet
Load More
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations