Hướng dẫn cách cắt file Word của bạn thành nhiều file nhỏ

Nếu bạn có một tài liệu Word đồ sộ và bạn cần cắt file Word này thành nhiều tài liệu nhỏ hơn thì hãy dành vài phút đọc hướng dẫn này. Gitiho sẽ chỉ cho bạn 2 cách để chia nhỏ file Word thành nhiều tài liệu dễ dàng và nhanh nhất.

Các cách cắt file Word nhanh nhất

Cách cắt file Word bằng dấu phân cách với VBA

Thay vì cắt file Word thành nhiều phần bằng cách thủ công thì phương pháp này sẽ giới thiệu một VBA (ứng dụng lập trình cơ bản trong Microsoft Office) theo dấu phân cách. Bạn hãy làm theo các bước sau để tách file Word nhé.

VBA: Tách file Word thành nhiều File word khác bằng Delimiter

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

huong-dan-cach-chia-mot-tai-lieu-thanh-nhieu-tai-lieu-trong-word

Như vậy là chúng ta đã hoàn thành thao tác tách file Word thành nhiều file nhỏ rồi!

Và trước khi thành thạo VBA, hãy chắc chắn mình đã thành thạo cách dùng Word từ cơ bản đến nâng cao. Bạn có thể tham khảo khóa học Word chẳng hạn Tuyệt đỉnh Word của Gitiho giúp bạn tối ưu hóa hiệu suất công việc soạn thảo văn bản với các kỹ thuật và tips hữu ích:

Một số lưu ý khi cắt file Word bằng mã VBA:

Xem thêm: Cách tạo AutoText giúp soạn thảo văn bản nhanh trong Word

Cách cắt file Word bằng Page với VBA

Chúng ta sẽ học thêm một phương pháp cắt file Word sử dụng VBA. Đây là một ứng dụng lập trình cơ bản khác (VBA) có thể giúp bạn tách file Word thành nhiều tài liệu nhỏ bằng Page trong Word. Hãy làm như sau:

Mã VBA: tách tài liệu thành nhiều tài liệu bằng Page trong 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

Khi sử dụng mã VBA này để chia nhỏ file Word, bạn cần lưu ý rằng các tài liệu được tách sẽ được lưu vào cùng nơi với tệp gốc.

Xem thêm: Hướng dẫn sử dụng VBA để sao chép dữ liệu từ Excel sang Word

Tổng kết

Vậy là chúng ta đã thực hành 2 phương pháp cắt file Word thành nhiều file nhỏ bằng cách sử dụng VBA. Có thể bạn vẫn còn xa lạ với VBA trong Word, vậy thì từ ngày hôm nay hãy bắt đầu tìm hiểu về tính năng này của Word nhé. Mình chắc chắn rằng bạn sẽ mở khóa được rất nhiều tính năng hữu ích không tưởng đấy.

Gitiho chúc bạn thành công!

Link nội dung: https://world-link.edu.vn/cach-tach-trang-trong-word-thanh-file-rieng-a57015.html