跳到主要內容

如何將文檔分成多個單詞?

作者:阿曼達李 最後修改時間: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  /  將頁面匯出為圖像  /  一次列印多個文件...

內容編輯: 批量查找和替換 跨多個文件  /  調整所有圖片的大小  /  轉置表行和列  /  將表格轉換為文字...

🧹 輕鬆清潔: 移開 多餘的空間  /  分節符  /  所有標題  /  文本框  /  超鏈接  / 如需更多拆卸工具,請前往 刪除群組...

創意插入: 插入 千位分隔符  /  複選框  /  單選按鈕  /  QR Code  /  條碼  /  對角線表  /  公式標題  /  圖片說明  /  表格標題  /  多張圖片  / 發現更多 插入群組...

🔍 精準選擇:精確定位 特定頁面  /    /  形狀  /  標題段落  / 增強導航功能 更多 選擇功能...

星級增強: 導航到任何位置  /  自動插入重複文字  /  在文檔視窗之間切換  /  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